Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Import could not be resolved" reported by Pyright

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?

like image 229
Ben Avatar asked Apr 06 '20 04:04

Ben


2 Answers

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"
}
like image 50
Ben Avatar answered Nov 17 '22 05:11

Ben


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

like image 7
Sanjay Sikdar Avatar answered Nov 17 '22 04:11

Sanjay Sikdar