Kit*_*adr 24 opencv pylint visual-studio-code
我在opencv项目上运行pylint,我在VS代码中收到许多关于不存在的成员的pylint错误.
示例代码:
import cv2
cv2.imshow(....)
Run Code Online (Sandbox Code Playgroud)
获得的错误:
但是,代码运行正常,没有任何错误.
版本:pylint 1.8.1,astroid 1.6.0
Gab*_* P. 52
这是来自pylint.您可以生成在该命令你的项目的根pylint的配置文件:(我觉得这是有帮助的,如果你在一个团队或在不同的计算机从同一回购工作)
pylint --generate-rcfile > .pylintrc
Run Code Online (Sandbox Code Playgroud)
在生成的.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=
Run Code Online (Sandbox Code Playgroud)
添加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
Run Code Online (Sandbox Code Playgroud)
保存文件.lint错误应该消失.
Man*_*kla 38
完成,它对我有用
注意:确保您选择“首选项:打开设置(JSON)”,而不是“首选项:打开默认设置(JSON)”
设置文件看起来像
{
"workbench.iconTheme": "vscode-icons",
"python.dataScience.sendSelectionToInteractiveWindow": true,
"kite.showWelcomeNotificationOnStartup": false,
"python.dataScience.askForKernelRestart": false,
"python.dataScience.jupyterServerURI": "local",
"python.pythonPath": "/usr/bin/python3",
"workbench.colorTheme": "Monokai",
"vsicons.dontShowNewVersionMessage": true,
"python.linting.pylintArgs": ["--generate-members"] }
Run Code Online (Sandbox Code Playgroud)
小智 26
尝试导入CV2这样的:from cv2 import cv2。
Zai*_*lux 13
这里是 MS V Code 中 settings.json 文件的代码片段
"python.linting.pylintArgs":["--extension-pkg-whitelist=cv2"]
Run Code Online (Sandbox Code Playgroud)
Pra*_*l M 11
是的,因为尚未安装扩展程序.设置此:extension-pkg-whitelist = cv2,你很高兴.但是,它可能无法检测到cv2中实现的功能或模块
在 VSCode 中,编辑设置 JSON(Ctrl++ Shift、P>“首选项:打开设置 JSON)
然后,将以下内容粘贴到 JSON 中:
"python.linting.pylintArgs": [
... // prievious arguments
"--generated-members=cv2.*"
]
Run Code Online (Sandbox Code Playgroud)
不知道为什么,但其他解决方案(白名单等)对我不起作用,而且我不想创建该.pylintrc文件。
| 归档时间: |
|
| 查看次数: |
19656 次 |
| 最近记录: |