Jupyter Notebooks in VS Code using WSL 2 are not working
M

4

15

I want to use Jupyter Notebooks inside VS Code running within WSL 2. Regular Python works within WSL without a problem, that means the base conda enviroment is connected and I can run .py files. Moreover, I’m able to run the command jupyter notebook which will start the notebook server within WSL exposing the localhost to the Windows system.

However, I want to test the new Jupyter Notebook feature within VS Code, which is not working for me; VS Code shows: Jupyter Server: No Kernel and Python: Not Started (see screenshot below).

My testing machine is:

  • WSL 2 (using Pengwin distribution) on Windows 20H1 (19041.21)
  • VS Code 1.41 (having the Python extension installed)
  • Anaconda

What I did:

  1. Open WSL
  2. Open VS Code in my target directory (code .)
  3. Create a new Notebook file from the command palette Python: Create New Blank Jupyter Notebook
  4. Create dummy print("test")
  5. Run Cell will trigger the warning:

enter image description here

Is there anything I’m missing?

Manumission answered 2/2, 2020 at 10:22 Comment(5)
Did you set the server URI? Looks like the URI is too short. You set it with the 'Python: Specify local or remote Jupyter server for connections'. You should pick default if you haven't alreadyWaxplant
As you are using Windows Insider Build, it has many issue associated with accessing localhost. See this as example github.com/microsoft/WSL/issues/4353.Dandruff
Humn, it is actually working now, yet I don’t know what fixed it...Manumission
Any new info for this? Now that WSL2 is released to stable, I'm still having the issue the OP mentionedChesna
I'm having this issue on wsl2 as well. EDIT: it's working now. not sure why, i didn't change anything.Bethanybethe
S
5

The VSCode extensions on the windows side and the WSL side are independent of each other, and you need to install the python extension on the WSL side.

VSCode will prompt you to install them when you run .py file on the WSL side, but running .ipynb will not. This is probably the source of the problem.

Stites answered 27/5, 2023 at 3:35 Comment(0)
D
3

The VS Code insiders actually works out of box with Jupyter notebooks. Just remember to run code-insiders . instead of code ..

Another solution would be, according to this website, start the VS Code in windows, then use WSL 2 as a remote server.

Destructor answered 10/2, 2021 at 3:56 Comment(0)
D
1

The code installation on wsl2 needs a restart to work properly, I was told by a notification, and in the question's comments you may see people experiencing the same issue(' it's working now. not sure why'). So before looking upon any elaborate solution, just restart code.

Defiant answered 15/12, 2021 at 16:18 Comment(0)
A
0

So I struggle alot and found below solution:

If you are using Python3.11, sol is below:

python3.11 -m pip install --upgrade psutil
python3.11 -m pip install ipykernel
python3.11 -m ipykernel install --user --name=python3.11

I had problem with Python3.10, Python3.9 as well, I just run these commands with all of them.

Now I can use jupyter notebook in VS-code, Especially in WSL.

Asperges answered 9/4 at 10:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.