11

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

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

imantha
  • 2,676
  • 4
  • 23
  • 46

3 Answers3

15

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

zar3bski
  • 2,773
  • 7
  • 25
  • 58
1

Manage to figure it out. I was using jupyter in vscode, and in addition changing its (jupyter) environment - which was the correct one,

enter image description here

I also had to change .py file environments (which was a different env before)

enter image description here

And that removed the warnings.

imantha
  • 2,676
  • 4
  • 23
  • 46
  • How to change the .py environment? I do not have this option? – Atif Ali Apr 12 '22 at 12:47
  • 1
    Its on the bottom right hand side now after vscode update – imantha Apr 12 '22 at 16:12
  • This worked out for me. I installed pandas from within the virtual environment but VS code was looking for the global python and not the one from within the virtual environment (even though they were both the same version). Changing it to the one within the virtual environment (in VS code bottom right) seemed to do the trick. – Jose R Jun 10 '22 at 16:18
1

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

Ahsan Ali
  • 91
  • 1
  • 4