pythonvisual-studio-codepylance

Disable linter error of `method is not a known member of module "cv2"` from pylance in VSCode


{
    "terminal.integrated.defaultProfile.windows": "Ubuntu (WSL)",
    "workbench.colorTheme": "Monokai Pro",
    "editor.mouseWheelZoom": true,
    "python.analysis.autoImportCompletions": true,
    "flake8.args":[
        "--ignore=W293,W292,W291",
    ],
    "pylint.args":[
        "--extension-pkg-whitelist=cv2",
        "--generated-members=numpy.*, torch.*, cv2.*,  cv.*",
        "--disable=C0114,C0115,C0116"
    ],
    "python.analysis.typeCheckingMode": "basic",  // Pylance
    "python.analysis.fixAll": [],
    "editor.fontSize": 16,
    "workbench.preferredDarkColorTheme": "Monokai",
    "workbench.preferredHighContrastColorTheme": "Monokai",
    "files.autoSave": "afterDelay",
    "[python]": {
        "editor.formatOnType": true,
        "editor.defaultFormatter": "ms-python.autopep8"
    },
    "editor.rulers": [
        79
    ],
    "git.ignoreLimitWarning": true,
    "remote.SSH.remotePlatform": {
        "192.168.60.229": "linux",
        "192.168.60.230": "linux"
    },
    "githubPullRequests.pullBranch": "never",
    "vim.useCtrlKeys": false,
    "workbench.tree.indent": 4,
    "workbench.iconTheme": "vscode-icons",
    "isort.check": true,
    "window.zoomLevel": -1,
    "remote.autoForwardPortsSource": "hybrid",
    "workbench.editorAssociations": {
        "*.md": "default"
    },
    "markdown-preview-enhanced.previewTheme": "atom-dark.css",
    "git.openRepositoryInParentFolders": "never"
}

I have installed the pylance, pylint and flake8 extensions with configuring settings with cv2 yet it shows the linter error message "cvtColor" is not a known member of module "cv2". Could anyone help me with this linter setting problem? many thanks! enter image description here


Solution

  • I've been experiencing the same issue with vscode, pylint, and cv2. Looking at your settings.json, add parenthesis around the generated members.

    "pylint.args":[
        "--generated-members=(numpy.*, torch.*, cv2.*,  cv.*)",
    ],
    

    This is as per the documentation https://pylint.readthedocs.io/en/stable/user_guide/configuration/all-options.html#generated-members