29

enter image description here

I've just started using Pyright. Running it on files that run perfectly well I get plenty of errors.

This question is similar, but refers to one's own modules.

For example Import "numpy" could not be resolved. What does it mean, and how do I resolve it?

Ben
  • 12,614
  • 4
  • 37
  • 69

7 Answers7

62

On my computer I have 3 Pythons, a 3.6 from Anaconda, and a 2.7 & 3.7 that are regular python. Prompted by a nudge from this GH issue, I switched from the Anaconda 3.6 to the 3.7, and back again, and the problem went away.

the python chooser

I think that this is the case because your .vscode/settings.json (the following is mine), doesn't have that last line until you change your python, at which point, that last line is put in and Pyright has something to look at.

{
  "python.linting.enabled": true,
  "python.formatting.provider": "black",
  "python.pythonPath": "C:\\Users\\ben\\Anaconda3\\python.exe"
}
Ben
  • 12,614
  • 4
  • 37
  • 69
  • 1
    On macOS M1, it could be, e.g., `/opt/homebrew/anaconda3/bin/python`, if you have installed `anaconda` via brew like: `arch -arm64 brew install anaconda`. –  Mar 01 '21 at 17:32
  • 2
    The key `"python.pythonPath"` is no longer in use for the settings and is now `"python.defaultInterpreterPath"` – Damola Obaleke Oct 08 '22 at 19:47
8

python -m pip install -U pylint python -m pip install --upgrade pip

Open VS Code -> CTRL + SHIFT P -> Search 'select linter' [Python: Select Linter] -> Hit Enter and Select Pylint

If not solved. Try deactivate your environment pip install numpy in your global environment.

And if you are using Local Environment getting unresolved imports error then add In .vscode/settings.json "python.analysis.extraPaths": ["./path-to-your-code"], for example "python.analysis.extraPaths": [ "*.lib" ]

Sanjay Sikdar
  • 435
  • 4
  • 10
  • Updating the extra paths setting worked for me; however, I updated my workspace json settings rather than the global settings file. – Anil Dec 21 '22 at 17:46
5

I'm not sure if you have already fixed this, but I was having a lot of troubles with stuff I got with pip install and they were installed successfully, but when I tried to import them, they didn't import

I found out that for me, some of the installs get installed to a separate folder, and not the correct folder that they need to be in to import.

If you try installing it again with pip install, then it will say you already have it installed and it will give you the location where the file is, and I copied the files from there and pasted them into the correct location which is (on windows)

C:\Users\{Username}\AppData\Local\Programs\Python{Python Version}\Lib\site-packages

I was trying to find a place to share this and this was the closest to the issue, so I hope it helps!

edit: the above answer is definitely a short-term solution, but I was able to fix this completely by reinstalling pip. I forgot how I reinstalled it, but I thought I'd add this to point you in the right direction if you need a long-term solution

Glenn
  • 84
  • 1
  • 6
2

I work in Local Environment and I can solve this problem by going to Setting.json and search python analysis but I just addressed this path C:\Users{Username}\AppData\Local\Programs\Python{Python Version}\Lib\site-packages

1

Setting the interpreter as Python with current version worked just fine for me. You can do it by clicking Python in lower left corner and selecting your project.

octo
  • 11
  • 1
  • 3
0

I solved mine by just adding the conda executable path.

  • 3
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 19 '22 at 04:56
0

Here is how I solved it on my Mac. In a terminal window (system's terminal not the vscode one) type:

which python

On my setup I got: "/Volumes/Attic/miniforge3/bin/python" Then in VsCode copy that whole path to Setting > Extensions > Default Interpreter Path

That's it. That instantly resolved the issue.

I also did the same for Setting > Extensions > Conda Path populating that field with the path returned by which conda But that's a separate issue.