首先说明我的情况,情况不一样可能不是这么回事。我是Mac OS
系统(Linux
可能类似)使用Anaconda
安装了Python
环境和PyQt5
包,然后呢,用VS Code
写代码的时候,会提示这个错误。

But!
VS Code
中pylint
提示这个错误呢,实际上没有错误,因为环境和包都没有问题,写的脚本在终端都可以正常运行,就是VS Code
给你提示这个错误,所以很烦呀,明明没有问题,看着错误就特别碍眼。

网上搜了搜,找到一个比较可信的答案
pylint doesn't load any C extensions by default, because those can run arbitrary code.
解决办法就是在项目主目录下新建一个.pylintrc
文件,然后在这个文件里添加一行
extension-pkg-whitelist=PyQt5
比如我在test
文件夹下新建了这个文件,并写上这句话。

重启VS Code
,可以看到,问题已经不在了。

我觉得类似的问题都可以在这个扩展包白名单里加上需要导入的包。
网友评论