21

Using the Ubuntu bash terminal on Windows 10 (installation instructions here), I installed Anaconda and have been using Jupyter notebooks without a problem. Unfortunately, Jupyter is unable to locate a runnable browser from within the subsystem, so I have to copy and paste the link it outputs in the terminal - but that is workable. The main issue comes when I try to open multiple notebooks. Normally, Jupyter would detect that a port (8888 by default) is already being used and make a new one, but it seems to fail to detect this so that when I use the link it generates, I end up looking at the first notebook I opened instead of the new one.

Any idea what the issue might be? And, if not, how I can manually get around this?

Grayscale
  • 1,462
  • 1
  • 13
  • 20
  • Have you trying installing firefox or other browser to your subsystem and then try to run the browser with your choice of xwindows clients? – scrappedcola Jun 15 '18 at 20:29
  • @scrappedcola No, I have not yet set up an X server to work with WSL. Do you know if there is a substantial performance disadvantage to do so? – Grayscale Jun 15 '18 at 22:04
  • I haven't noticed, but it probably depends heavily on the type of computations you are doing. – scrappedcola Jun 17 '18 at 14:48
  • I used solutions from both answers `jupyter notebook --no-browser --port 9888`. Works for me – John Karasev Feb 13 '21 at 01:00

4 Answers4

22

try:

jupyter notebook --no-browser
Faymek Feng
  • 221
  • 2
  • 3
14

Update:
For some, the original answer below should still work.
For others, who get an additional error related to a tcgetpgrp failed: Not a tty message, there is no real fix at the moment. (See this issue on GitHub)
Therefore, you need to use jupyter notebook --no-browser or set c.NotebookApp.open_browser = False in the config file $HOME/.jupyter/jupyter_notebook_config.py.

Original answer:
I had the problem that Jupyter didn't find a file (complete error message in German):

Start : Dieser Befehl kann aufgrund des folgenden Fehlers nicht ausgeführt werden: Das System kann die angegebene
Datei nicht finden.
In Zeile:1 Zeichen:1
+ Start "file:///home/nico/.local/share/jupyter/runtime/nbserver-1164-o ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOperationException
    + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

Jupyter did work, but it didn't open my browser, when I typed jupyter notebook.

I found a very simple solution to this:

  1. Create the Jupyter Config file:
jupyter notebook --generate-config

or

touch $HOME/.jupyter/jupyter_notebook_config.py
  1. Now add the following line to the config file (by using nano or any other text editor):
c.NotebookApp.use_redirect_file = False

Now, my WSL uses the wslview command to open the default browser in Windows. (I think)

If wslview . does nothing, you might need to manually install wslu.

Side note:
This solution also works for jupyter lab, but you have to use c.LabApp.use_redirect_file = False in $HOME/.jupyter/jupyter_lab_config.py.
Or even better c.ServerApp.use_redirect_file = False in $HOME/.jupyter/jupyter_server_config.py.

Nico G.
  • 487
  • 5
  • 12
  • I had a working setup that started throwing this error message all of a sudden. Turns out all I had to do was restart wsl as shown in this question: https://stackoverflow.com/questions/66744219/jupyter-lab-networkerror-running-on-wsl2 – Scott Sep 14 '21 at 18:08
11

Assign different port number manually when you start the notebook. For example:

jupyter notebook --port=8889

Q. Qiao
  • 767
  • 6
  • 17
  • 1
    Ah thanks! This fixes the problem. Any idea why Jupyter might fail to detect the port already in use? – Grayscale Jun 15 '18 at 21:58
4

I had similar issue with browser, I got

No web browser found: could not locate runnable browser.

I installed WSLU https://github.com/wslutilities/wslu. Then I got

Start : This command cannot be run due to the error: The system cannot find the file specified.
At line:1 char:1
+ Start --h
+ ~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

jupyter-notebook does not supply url as a parameter to wlsview. It passes a path with file to browser. eg

file:///home/myhome/.local/share/jupyter/runtime/nbserver-5058-open.html

with actual url

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="refresh" content="1;url=http://localhost:8888/tree?token=19b5f1fefb13f5fc315b05991175d1f8cb5ada9baaca6804" />
    <title>Opening Jupyter Notebook</title>
</head>
<body>

<p>
    This page should redirect you to Jupyter Notebook. If it doesn't,
    <a href="http://localhost:8888/tree?token=19b5f1fefb13f5fc315b05991175d1f8cb5ada9baaca6804">click here to go to Jupyter</a>.
</p>

</body>
</html>

Create a file jupyter-notebook-browser with a content to extract actual url

#!/bin/bash
file=$(echo "$1" | sed 's/file:\/\///')
url=$(grep -oP 'href="\K([^"]*localhost[^"]+)' "$file")
wslview "$url"

then run jupyter-notebook --browser=jupyter-notebook-browser

or define BROWSER variable and run

export BROWSER="jupyter-notebook-browser"
jupyter-notebook
Vitek
  • 71
  • 5
  • The second option does not work for me. The jupyter notebook runs in WSL and I get two paths, one file:// and other localhost and file option automatically opens in the browser. However, it just shows a blank page and does not redirect to the notebook. If I open the localhost path, then it shows the notebook. Is it possible that jupyter-notebook opens the localhost path directly? – Chintan Pathak Jan 07 '19 at 23:27
  • This works for me; i find the error message quite cryptic and it is only your answer that explains that it has something to do with (in)ability to locate a browser. Thank you. – Vojta F Jan 08 '20 at 08:23
  • 1
    There is no need to install wslu. Replace the last script line `wslview "$url"` with `cmd.exe /C start "$url"`. – Michael Veksler Aug 24 '20 at 08:12