Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS/Pylance warning: import "module" could not be resolved

Hi I am getting the following warning (A squiggly line underneath imports), import "numpy" could not be resolved Pylance(reportMissingModuleSource). There is no issues with executing the code - works fine, just the warning (squiggly line).

In the following github page, it states to change Settings.JSON with following line "python.analysis.extraPaths": ["./sources"].

  • https://github.com/microsoft/pylance-release/blob/main/TROUBLESHOOTING.md#unresolved-import-warnings

However this didn't work. I also tried adding the path to the current directory followed by "sources" as show in the image. But it didnt work either.

I am opening vs code from this entry point /home/imantha/workspace/python using bash with code . command.

Could anyone know how I add the correct path.

enter image description here

like image 365
imantha Avatar asked Jan 25 '26 15:01

imantha


2 Answers

If I understand your problem correctly, your python environment is properly set (for you are able to run your code) but your IDE (Vs code) points import errors.

That is probably because your IDE does not know which python environment use for your current project (which seems to live somewhere in /home/imantha/workspace/python). You need to set it to get rid of this warning https://code.visualstudio.com/docs/python/environments

like image 184
zar3bski Avatar answered Jan 27 '26 04:01

zar3bski


I solved this issue by just changing the Python Interpreter from Visual Studio Code . I changed it from recommended to global interpreter by pressing CTRL+SHIFT+P (Command Palette) and then typing Python: Select Interpreter as shown below:

select interpreter from vscode

like image 38
Ahsan Ali Avatar answered Jan 27 '26 06:01

Ahsan Ali



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!