-1

I am on Windows 10, running WSL Ubuntu as well. Visual Studio Code states that PyLance cannot resolve imports. My interpreter is the basic Python 3.11 .exe in Windows, not WSL.

In WSL, I have activated a virtual environment and installed packages, with NumPy as an example. When I run 'code .', Visual Studio Code opens as expected, but there are unresolved imports. I've worked for about 3 hours on this, uninstalling extensions and reinstalling, trying everything that ChatGPT could think of. Why does PyLance not see my imports? I'm not sure what other info anyone would need to be able to solve this, but I am happy to provide any.

  • Do you type `code .` in `WSL` or in `Windows PowerShell`? – doneforaiur Aug 09 '23 at 18:09
  • I type code . in WSL, and it pulls up a new vscode window with my project directory. – Lucas Hill Aug 09 '23 at 18:21
  • Could you include a screenshot of the VS Code? I'm not sure but I'm curious. :^) – doneforaiur Aug 09 '23 at 18:26
  • https://i.stack.imgur.com/KlsXg.png – Lucas Hill Aug 09 '23 at 18:30
  • OH! Have you installed the WLS extension in VS Code? – doneforaiur Aug 09 '23 at 19:05
  • Everytime I try to, it tells me to reopen the folder in an WSL vscode window. When I do, it won't let me install it and gets stuck in a loop. It also doesn't like to stay in my extensions: it keeps disappearing every time I reload vscode. – Lucas Hill Aug 09 '23 at 19:29
  • Now, that's the root cause of your Pylance problem, I think. I know it's a lot of hassle, but could you install VS Code Insider inside the WSL? – doneforaiur Aug 09 '23 at 19:37
  • 1
    I installed [Anaconda](https://www.anaconda.com) and set it as my interpreter. I think this will work for most common packages. – Lucas Hill Aug 09 '23 at 20:26
  • Interesting. So the interpereter was Python that was installed on Windows? – doneforaiur Aug 09 '23 at 21:34
  • Can you run the code normally in the event of a pylance warning? – MingJie-MSFT Aug 10 '23 at 01:30
  • show what VS Code says in the problem indicator. – starball Aug 10 '23 at 08:38
  • @doneforaiur Really, really don't advise installing VSCode in the WSL/Linux instance. It will work, but the Windows/WSL integration is *so* much better that it's preferable for Lucas to try to resolve that particular issue. – NotTheDr01ds Aug 11 '23 at 11:51
  • Oh, thanks! Could you point me to some links as I want to understand what are the benefits. :^) – doneforaiur Aug 11 '23 at 11:54
  • @LucasHill Can you edit your question to include more info on the problem you mentioned with installing the WSL extension in VSCode? As doneforaiur mentioned, without this extension in place, you are going to have issues with WSL development. – NotTheDr01ds Aug 11 '23 at 11:54
  • 1
    @doneforaiur [This MS page](https://learn.microsoft.com/en-us/windows/wsl/tutorials/wsl-vscode) has a fairly good overview, but in addition to that, VSCode for Windows is going to be far faster and more responsive than the Linux version when running under WSL. The integration is pretty impressive - The extension provides a server shim that is installed into the Linux distribution. VSCode in Windows is then able to connect to that server to access files and processes in WSL directly. – NotTheDr01ds Aug 11 '23 at 11:56
  • @LucasHill Also, you mention that your Python interpreter is the Windows `.exe` rather than the Linux version. Is this intentional? If you are starting VSCode from inside WSL, you'll need to use the Linux version of Python, since the Windows version isn't going to understand Linux filesystems/processes/etc. – NotTheDr01ds Aug 11 '23 at 11:58

0 Answers0