G02-VSCode Pylint配置

·

0 min read

在使用VSCode编写OpenCV代码时,在使用cv2包时,会看到pylint给出如下的error:

[pylint] E1101:Module 'cv2' has no 'imread' member

这是因为pylint没有获取到cv2包的内部信息,为此我们需要修改pylint的相应设置。

使用F1 输入Preferences:Open Settings (JSON)打开用户设置,在其中添加如下几行配置:

"python.linting.pylintArgs": [
        "--extension-pkg-whitelist=cv2",
        "--disable=all",
        "--enable=F,E,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode"
    ]

其中,"--extension-pkg-whitelist=cv2"是将cv2加入白名单之中不做报错,而后的几行是官方推荐的提示过滤配置。

参考:

  1. cv2 module members are not recognized
  2. Linting Python in Visual Studio Code