VSCode not resolving installed python dependencies

67 Views Asked by At

I have a python project for which I have activated a virtualenv and installed everything in requirements.txt.

This has been done manually through

python -m venv /path/to/new/virtual/environment

and

pip install -r requirements.txt

However the VSCode fails to resolve the additional dependencies (and marks the corresponding imported libraries with a squiggled line as per the screenshot below)

Is there something additional that needs to be configured on VSCode level to make this work?

enter image description here

2

There are 2 best solutions below

2
Bunyo On

Make sure you activate your virtual environment.

This can be done by executing the activate script in the terminal:

/pathtovenv/venvname/scripts/activate

0
MingJie-MSFT On

This was usually caused by python interpreter.

You could use shortcuts "Ctrl+Shift+P" and type "Python: Select Interpreter" to choose your python interpreter which you installed the package in.

If you ensure that you've chosen the correct python interpereter, you could add the following codes to your settings.json:

"python.analysis.extraPaths": [
    "/path/to/directory/where/requests/is/installed"
]