Home > front end >  How do I launch Jupyter Notebook in WSL using PowerShell?
How do I launch Jupyter Notebook in WSL using PowerShell?

Time:09-21

What I want to do is to create a shortcut for Jupyter Notebook which has to run in WSL (because all my python packages are there). For this AFAIK I should create PowerShell script which runs WSL with command to launch Jupyter Notebook, something like this:

wsl -e bash -c "jupyter notebook"

But this command gives bash: jupyter: command not found although if I do it step by step, it launches Jupyter:

PS C:\Users\Artem> wsl
(base) artem@LAPTOP-O4C3S1UK:/mnt/c/Users/Artem$ jupyter notebook

All tested commands suffer from one of these problems:

  1. bash cannot find the command (neither jupyter or anaconda)
  2. Some terminal laucnhes and instantly disappears

I am not proficient enough in PowerShell/WSL scripting so asking for advice how to do it properly.

P.S. I guess I can install jupyter for Windows and add kernels from WSL, but I want to know if problem can be solved in the way described above.

CodePudding user response:

You can solve it by using the absolute path of jupyter. Here is how to do that

# this code should run in WSL
# get the absolute path of jupyter
which jupyter
# output
# /home/sheep/miniconda3/envs/flask/bin/jupyter

When you run the code in WSL, you will get the absolute path of jupyter.

Then, you will be able to lanuch jupyter by running wsl -e bash -c "/home/sheep/miniconda3/envs/flask/bin/jupyter notebook" in PowerShell.

Note: /home/sheep/miniconda3/envs/flask/bin/jupyter is the absolute path of jupyter in my computer.You should replace it with yours.

CodePudding user response:

It sounds like required initializations are performed in your ~/.bashrc file, which bash by default only loads in interactive sessions, not when you submit a command to execute with -c.

However, you can explicitly tell bash to consider a session interactive, using the -i option.

Therefore, try the following (note the -i):

wsl -e bash -ic "jupyter notebook"
  • Related