PyLint无法识别cv2成员 [英] PyLint not recognizing cv2 members
问题描述
我正在opencv项目上运行pylint,并且在VS代码中收到很多关于pylint的错误,提示不存在成员.
I am running pylint on an opencv project and I am getting many pylint errors in VS code about members not being present.
示例代码:
import cv2
cv2.imshow(....)
获得的错误:
但是,代码可以正确运行,没有任何错误.
However , the code runs correctly without any errors.
版本:pylint 1.8.1,astroid 1.6.0
Versions : pylint 1.8.1 , astroid 1.6.0
推荐答案
这是来自pylint.您可以使用以下命令在项目的根目录中生成pylint配置文件: (如果您在同一回购中的团队中或在不同的计算机上工作,我会发现这很有帮助)
This is from pylint. You can generate a pylint config file in the root of your project with this command: (I find this to be helpful if you work in a team or on different computers from the same repo)
pylint --generate-rcfile > .pylintrc
在生成的.pylintrc文件的开头,您将看到
At the beginning of the generated .pylintrc file you will see
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code.
extension-pkg-whitelist=
添加cv2,这样您最终会得到
Add cv2 so you end up with
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code.
extension-pkg-whitelist=cv2
保存文件. 棉绒错误应该会消失.
Save the file. The lint errors should disappear.
这篇关于PyLint无法识别cv2成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!