Using Jupyter with Windows Subsystem for Linux

跟風遠走 提交于 2020-06-24 11:52:31

问题


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?


回答1:


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

jupyter notebook --port=8889




回答2:


try:

jupyter notebook --no-browser



回答3:


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


来源:https://stackoverflow.com/questions/50882266/using-jupyter-with-windows-subsystem-for-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!