Search code examples
pythonvisual-studio-codepylint

Pylint gives errors in Visual Studio Code, but the code runs


I am getting red underline on parts of Python code in Visual Studio Code. The code runs well anyway and everything works, but it's depressing to have red file names in the explorer tree in Visual Studio Code and even in the code, too.

Example 1:

from win32api import GetSystemMetrics

Error:

No name 'GetSystemMetrics' in module 'win32api'pylint(no-name-in-module)

Example 2:

pupil_remote = ctx.socket(zmq.REQ)

Error:

Module 'zmq' has no 'REQ' member pylint(no-member)

How can I fix this?


Solution

  • This is a really tricky thing.

    As you know, you can have several Python environments configured in Visual Studio Code, and alternate among them doing click in the left side of bottom line.

    What worked for me was:

    • Create a virtual environment directly below the main folder of your Visual Studio Code project (see https://docs.python.org/3/library/venv.html)

    • When you start (add) your project folder to a Visual Studio Code workspace, it has to ask about Python interpreter Select Python interpreter

    • From the list, select manually add enter image description here

    • Select the Python under your folder in env/bin/python3

    • If it does not ask you when start, you can go to command window, and search the option

      Enter image description here