Pylint "Unresolved Import" Error in Visual Studio Code

Pylint unresolved import error in Visual Studio Code

In your workspace settings, you can set your Python path like this:

{
"python.defaultInterpreterPath": "/path/to/your/venv/bin/python",
}

Unresolved import error in VSCode with PyDev?

According to the information you provided, "Unresolved import: redisPyDev" is provided by the VS Code extension "PyDev". If you do not use this extension, please try to "disable" it.

Usually, when we use python in VS Code, many of its functions are provided by the Python extension. When I did not install the module "redis", here is the "unresolved import'redis'" information provided by the python extension:

Sample Image

After we installed the module "redis", then reload VS Code, no errors or warnings are displayed here:

Sample Image

(False) import error warning with global PyLint in virtual environment in Visual Studio Code

Very sorry for my previous answer, I had modified the pylintArgs before, so I have not found out the problem.

You can add this in the settings.json:

"python.envFile": "${workspaceFolder}/.env",

And create a file named .env under the workspace folder, and add this in it:

PYTHONPATH=/Users/pazifik/.virtualenvs/fun-image-scraper/lib/python3.9/site-packages

Explain:

Although you have selected the virtual environment in the VSCode, and you can find the PYTHONPATH has been modified in the terminal, but the pylint did not route through the terminal, so it will not get the modified PYTHONPATH.

When the terminal settings are used, PYTHONPATH affects any tools that
are run within the terminal by a user, as well as any action the
extension performs for a user that is routed through the terminal such
as debugging. However, in this case when the extension is performing
an action that isn't routed through the terminal, such as the use of a
linter or formatter, then this setting will not have an effect on
module look-up.

When PYTHONPATH is set using an .env file, it will affect anything the
extension does on your behalf and actions performed by the debugger,
but it will not affect tools run in the terminal.

You can refer to the official docs.

Python unresolved import VisualStudio

From your comment on pip -V, running "pip install.." in the VS Code terminal will install to Python 3.6. You original posts states you are using Python 3.9.0 and I assume this is displayed in the very bottom left of the VS Code window.

Try to install in the VS Code terminal using the correct version of pip like:
pip3.9 install....

You can also switch to the 3.6 Python interpreter in VS Code

  1. Click the version 3.9.0 in the bottom left of VS code.
  2. Ctrl+Shift+P > search Python: Select Interpreter


Related Topics



Leave a reply



Submit