解决vim中No name 'QWidget' in module 'PyQt5.QtWidgets'等问题
Posted on 2020-08-17 19:05 cxysailor 阅读(712) 评论(0) 收藏 举报 在使用vim写PyQt5的代码时,导入QWidget等模块时提示No name 'QWidget' in module 'PyQt5.QtWidgets',虽然代码能正常运行,但是这个提示看着不爽。
网上查来的,说出现这个的原因是:pylint doesn't load any C extensions by default, because those can run arbitrary code.(pylint默认情况下不加载任何C扩展,因为它们可以运行任意代码。)
解决方法:
在项目根目录新建一个文件.pylintrc
写入:extension-pkg-whitelist=PyQt5这么一句即可以解决.
以上的方法在Manjaro20.0.3版本中不起作用了。
在
官网上是这么说的
Pylint and C extensions
If you are getting the dreaded no-member error, there is a possibility that either pylint found a bug in your code or that it actually tries to lint a C extension module.
Linting C extension modules is not supported out of the box, especially since pylint has no way to get an AST object out of the extension module.
But pylint actually has a mechanism which you might use in case you want to analyze C extensions. pylint has a flag, called extension-pkg-whitelist, through which you can tell it to import that module and to build an AST from that imported module:
$ pylint --extension-pkg-whitelist=your_c_extension
Be aware though that using this flag means that extensions are loaded into the active Python interpreter and may run arbitrary code, which you may not want. This is the reason why we disable by default loading C extensions. In case you do not want the hassle of passing C extensions module with this flag all the time, you can enable unsafe-load-any-extension in your configuration file, which will build AST objects from all the C extensions that pylint encounters:
$ pylint --unsafe-load-any-extension=y
Alternatively, since pylint emits a separate error for attributes that cannot be found in C extensions, c-extension-no-member, you can disable this error for your project.
解决方法 - 在项目的根目录生成一个.pylintrc文件
# 切换到项目根目录下,在终端命令行输入如下命令
1 ❯ pylint --extension-pkg-whitelist=PyQt5 --unsafe-load-any-extension=y --generate-rcfile > .pylintrc
# 这里设置了两个参数:
--extension-pkg-whitelist=PyQt5
--unsafe-load-any-extension=y
[1] lint是最著名的C语言工具之一,是由贝尔实验室SteveJohnson于1979在PCC(PortableC Compiler)基础上开发的静态代码分析,一般由UNIX系统提供。
浙公网安备 33010602011771号