Search code examples
pythonvisual-studio-codepython-venv

Visual Studio Code cannot properly reference packages in the virtual environment


I am using VSCODE for my Python development on Windows 10.

As shown in the screenshot below, I use a virtual environment, and my virtual environment includes required libraries.

However, VSCODE shows the following problems:

  • "pyplot": Unknown word.
  • "numpy": Unknown word.

The program runs fine. I just need to fix the two problems pointed in the screenshot below:

enter image description here

It seems that some parts of VSCODE are not considering my virtual environment and try to find the unknown words in the Python installation outside the virtual environment.

How can I properly eliminate the above two "Unknown word" problems?


Solution

  • As an editor, VS Code itself does not display "Unknown word" information. According to the screenshot information you provided, the "Unknown word" information is provided by cSpell.

    In VS Code, we use the Linting function provided by the python extension (it contains Pylint, flake8, mypy, etc.) to analyze the python code, and it will display the problems in the code on the VS Code terminal. (Of course, some python language services will also display problems from the code.)

    It is recommended that you use the python code analysis tool Pylint when analyzing python code in VS Code. In the code in this thread, it will not display the "Unknown word" message:

    enter image description here

    Reference: The use of Pylint in VS Code.