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
保存文件.lint 错误应该会消失.
Save the file. The lint errors should disappear.
这篇关于PyLint 无法识别 cv2 成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!