What to do if Jupyter Notebook on WSL does not start automatically in your browser

For some reason, I returned from Mac to Windows (second time), and when I ran jupyter notebook on WSL in the same way as Mac, I encountered an event that the browser did not start automatically, so I will explain how to deal with it. It may not be enough to introduce it again, but I could not find any information in Japanese even if I googled with the error message, so I will expose it here.

Environment confirmed operation

Event

After installing jupyter with pip install, when I run jupyter notebook, the following error is displayed and it does not start automatically in the browser.

$ jupyter notebook
[I 01:39:20.094 NotebookApp] Serving notebooks from local directory: /mnt/c/workspace
[I 01:39:20.094 NotebookApp] The Jupyter Notebook is running at:
[I 01:39:20.094 NotebookApp] http://localhost:8888/?token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[I 01:39:20.095 NotebookApp]  or http://127.0.0.1:8888/?token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[I 01:39:20.095 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 01:39:20.116 NotebookApp]

    To access the notebook, open this file in a browser:
        file:///home/wsluser/.local/share/jupyter/runtime/nbserver-xxxx-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
     or http://127.0.0.1:8888/?token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Start : This command cannot be run due to the error: The system cannot find the file specified.
At line:1 char:1
+ Start "file:///home/wsluser/.local/share/jupyter/runtime/nbserver-xx ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOperationException
    + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

It seems to occur because the path of nbserver-xxxx-open.html on WSL cannot be referenced from the browser (Windows) side, but it starts when jumping to the URL of http: // localhost: 8888 /? Token = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx I will.

Correspondence method # 1

Execute with --NotebookApp.use_redirect_file = False.

$ jupyter notebook --NotebookApp.use_redirect_file=False

It is troublesome to specify the option every time, so set an alias appropriately and execute it.

$ echo "alias jn='jupyter notebook --NotebookApp.use_redirect_file=False'" >> ~/.bashrc
$ source ~/.bashrc
$ jn

Correspondence method # 2

Run with --generate-config and set c.NotebookApp.use_redirect_file = False in the generated config file. Then run without options.

//Generate config
$ jupyter notebook --generate-config
Writing default config to: /home/wsluser/.jupyter/jupyter_notebook_config.py

//Check the default settings
$ grep use_redirect_file ~/.jupyter/jupyter_notebook_config.py
#c.NotebookApp.use_redirect_file = True

//Uncomment and change to False
$ sed -i -e 's/#c.NotebookApp.use_redirect_file = True/c.NotebookApp.use_redirect_file = False/g' ~/.jupyter/jupyter_notebook_config.py

//Check the changed settings
$ grep use_redirect_file ~/.jupyter/jupyter_notebook_config.py
c.NotebookApp.use_redirect_file = False

//Run without options
$ jupyter notebook

reference

Recommended Posts

What to do if Jupyter Notebook on WSL does not start automatically in your browser
What to do when the graph does not appear in jupyter (ipython) notebook
What to do if NotADirectoryError: [Errno 20] Not a directory:'xdg-settings' appears in jupyter notebook
jupyter notebook does not start on mac fish
How to fix a bug that jupyter notebook does not start automatically
What to do if sys / cdefs.h does not exist
What to do if your Jupyter Notebook for beginners asks for a password or token
What to do if Python IntelliSense is not displayed in VS Code on Windows
What to do if Python does not switch from the System version in pyenv
Browser does not open automatically when jupyter notebook is started
What to do if you forget your login password on Manjaro Linux
What to do if pyenv install does not proceed with an error
How to hide warnings that do not affect execution in Jupyter Notebook
Notes on what to do when matplotlib scatter () / scatter3d () does not work
[Python] What to do if you get a ModuleNotFoundError when importing pandas using Jupyter Notebook in Anaconda
What to do if pipreqs results in UnicodeDecodeError
What to do if the latest Jupyter Notebook and nb extensions don't work
What to do if you get "Python not configured." Using PyDev in Eclipse
What to do if Japanese language support is not completely installed on Ubuntu 16.04
What to do if pip install fails in Xcode 5.1
What to do if SciPy installation fails on CentOS
What to do if a UnicodeDecodeError occurs in pip
What to do if pyenv is not enabled (zsh)
What to do when python3 type venv does not work well on Raspberry Pi
What to do if the progress bar is not displayed in tqdm of python
What to do when Python starts up in Anaconda does not come out unexpectedly
What to do if ʻarguments [0] .scrollIntoView ();` fails in python selenium
What to do when Japanese is not displayed on matplotlib
What to do if pip gives a DistributionError in Homebrew
What to do if the image is not displayed using matplotlib etc. in the Docker container
What to do if you get "coverage unknown" in Coveralls
What to do if a 0xC0000005 error occurs in tf.train.start_queue_runners ()
What to do if `pip install matplotlib` fails on Mac
What to do if you can't log in as root
Unable to display tensorboard in jupyter notebook on docker (solved)
What to do if you can't use WiFi on Linux
What to do if pip install mysqlclient fails on MacOS
What to do if you lose your EC2 key pair
CommandNotFoundError: Your shell has not been properly configured to use What to do if you get'conda activate'
What to do if the user name is changed and the pyenv library path does not pass
What to do if Python doesn't work on Git for Windows
What to do if you get a minus zero in Python
What to do if python says "fatal error:'stdio.h' file not found"
What to do if "Unnamed: 0" is added in to_csv-> read_csv in pandas
What to do if the inode is exhausted on EC2 Linux
Try to log in to Netflix automatically using python on your PC
What to do if you can't build your project with Maven
What to do if PyAudio cannot be installed on Python 3.7, 3.8, 3.9 on Windows
What to do if you can't use the trash in Lubuntu 18.04.
What to do if grep: empty (sub) expression appears on Mac grep
What to do if yum breaks
What to do if you get "The session could not be opened" when installing CentOS on VirtualBox
What to do if there is a decimal in python json .dumps
What to do if you can't find PDO in Laravel or CakePHP
What to do if you can't use scikit grid search in Python
What to do if ipython and python start up with different versions
What to do if your disk runs out due to MySQL binary logs
What to do if you get lost in file reference with FileNotFoundError
What to do if you get angry in TensorFlow v2 without attribute'app'
What to do if you get stuck during Anaconda installation on Linux
What to do if No Python documentation found for ... appears in pydoc