Visual Studio Code Pylance (report Missing Imports )

Viewed 11892

I keep getting error "X" could not be resolved Pylance(reportMissingImports) [ln 1, Col8]

I AM in fact a beginner, the basic youtube "fixes" are NOT working

  • View Command Pallet ... NOT working
  • Terminal pip install .... NOT working I am running the Zip install on my work computer and im guessing it has something to do with a directory. but i cant seem to figure it out. the bottom left corner shows the python version which is ( Pyhton 3.110a7 64-bit(windows store)
2 Answers

Pylance requires you to set the Python PATH:

If you're in Mac/linux, make use of :

which python3

And in windows:

where python

So that the path in which you're python is installed is returned

Copy that path.

Go to your vscode and open the settings.json file (CTRL + SHIFT + P, and type "settings.json" at search bar)

Add the following key to the json file

"python.defaultInterpreterPath": "/Users/YOURUSERNAME/opt/anaconda3/bin/python3"

This was just an example, the PATH could be something more like "C:/users/YOURUSERNAME/anaconda3/bin/python3" in case you're using windows.

The following documentation from python for vscode provides more information about how to configure Python for Visual Studio Code: https://code.visualstudio.com/docs/python/settings-reference

There’s a very comprehensive discussion on settings in VS Code here: https://stackoverflow.com/a/63211678/5709144.

In summary and with regard to this specific case, it’s better to change settings by going to (on a Mac) Code > Preferences > Settings.

Enter python.defaultInterpreterPath in the search box at the top of screen. The current path is shown in an editable text box.

Enter any path you like here - foobar, mother, whatever you like. It doesn’t matter as, if the path isn’t recognised by VS Code, VS Code lists those that are. The only reason you enter the path is to get the list of potential paths. Click on one of these accepted paths and you’re all set up.

Related