PyLint不识别cv2成员

2024-06-13 22:00:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我在一个opencv项目上运行pylint,在VS代码中我得到许多关于成员不存在的pylint错误。

示例代码:

import cv2
cv2.imshow(....)

获得的错误:

enter image description here

但是,代码运行正确,没有任何错误。

版本:pylint 1.8.1,astroid 1.6.0


Tags: 项目代码import版本示例错误成员cv2
3条回答

这里是MS V代码中settings.json文件的代码片段

"python.linting.pylintArgs":["--extension-pkg-whitelist=cv2"]

这是派林特寄来的。可以使用以下命令在项目的根目录中生成pylint配置文件: (如果您在同一个团队或同一回购协议的不同计算机上工作,我觉得这很有帮助)

pylint --generate-rcfile > .pylintrc

在生成的.pylintrc文件的开头,您将看到

# 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

# 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

保存文件。 绒布错误应该消失。

是的,因为扩展尚未安装。 设置这个:extension pkg whitelist=cv2,就可以了。 但是,它可能检测不到cv2中实现的功能或模块

enter image description here

相关问题 更多 >