"Import could not be resolved" reported by Pyright

Ben picture Ben · Apr 6, 2020 · Viewed 14.8k times · Source

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?

Answer

Ben picture Ben · Apr 7, 2020

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"
}