ah2Bwise
ah2Bwise

Reputation: 142

VS Code Pylance - Problem with Module Imports

My IDE was working fine last night. I created a launch.json file for a completely different app in a different directory but have since deleted it.

My code still processes correctly.

My virtual env is the same - all of my installed packages (pandas, numpy, etc) are being recognized by Pylance. The modules I am importing is the problem.

The modules I am trying to import are all .py files, are all in the same directory as the app.py file that I am running, and are functioning correctly, just as they have been.

Several of the modules being imported also import each other, and the problem is taking place in each module as well.

I have tried both uninstalling and reinstalling the Python and Pylance extensions, and restarting my machine and the same problem occurs.

imports

What am I missing?

Upvotes: 5

Views: 10492

Answers (1)

imbr
imbr

Reputation: 7672

My setup is a Ubuntu 22.04. My interpreter is a python virtual env (venv).

Even tough I had used cmd + shift + p or ctrl + shift + p. Then searched and selected python interpreter multiple times.

The only solution that worked for me was:

  • go to extensions->Pylance. Then on settings Python>Analysis:Extra Paths and add the path to my virtual env. site-packages folder (like /path/to/venv/lib/python3.x/site-packages/)

Or

  • The same by editing my settings.json file adding:

    "python.analysis.extraPaths": [
        "/path/to/venv/lib/python3.x/site-packages/"
    ]

Upvotes: 9

Related Questions