8

I am getting the following error while trying to import newly installed packages from pip:

Import "<package>" could not be resolved
Pylance(reportMissingImports)

After I restart VS Code, Pylance seems to then be able to recognise the package.

Is there any fix to this as it is very annoying?

informatik01
  • 16,038
  • 10
  • 74
  • 104
Harry Stout
  • 145
  • 1
  • 8
  • I would try to reinstall `pylance`. Also, I would keep an eye on the python version in case there are multiple versions of python – Anwarvic Oct 01 '21 at 13:54

2 Answers2

13

This question will happen when Pylance doesn't detect the module immediately. You may Reload Window from Command Palette to refresh the current project.

Pac0
  • 21,465
  • 8
  • 65
  • 74
Molly Wang-MSFT
  • 7,943
  • 2
  • 9
  • 22
  • 2
    to get to the command palette on a Mac use the shortcut `cmd + shift + P`. You can then search for *Reload Window*. – kindjacket May 31 '22 at 23:14
  • this did not solve the issue. Virtual env activated on wsl from vscode, latest version of python extension with pylance at time of this comment). The python script works fine with no error. – Pac0 Jan 14 '23 at 23:07
6

If you are using VS Code, open the command pallet and run "Python: Restart Language Server"

  • how is his answer any different than the one above though? they seem the same as far a providing supporting info, just different functions. – mike01010 Oct 19 '22 at 17:33
  • 2
    @mike01010 By reloading just the language server and not the whole window less things get reloaded. This is helpful as it takes less time and also leaves for example the current setup of terminal windows in tact. – Freek Mar 14 '23 at 13:21