在Linux的Windows子系统中使用Jupyter

2024-05-16 21:54:22 发布

您现在位置:Python中文网/ 问答频道 /正文

使用Windows 10(installation instructions here)上的Ubuntu bash终端,我安装了Anaconda,并且一直在使用Jupyter笔记本,没有问题。不幸的是,Jupyter无法从子系统中找到一个可运行的浏览器,所以我必须复制并粘贴它在终端中输出的链接-但这是可行的。主要问题是当我试图打开多个笔记本时。通常,Jupyter会检测到一个端口(默认情况下是8888)已经被使用并生成一个新的端口,但它似乎无法检测到这一点,因此当我使用它生成的链接时,我最终会看到我打开的第一个笔记本,而不是新的。

你知道问题是什么吗?如果没有,我怎么能手动绕过这个?


Tags: 端口bash终端here链接粘贴ubuntuwindows
3条回答

尝试:

jupyter notebook --no-browser

我对浏览器也有类似的问题

No web browser found: could not locate runnable browser.

我安装了WSLUhttps://github.com/wslutilities/wslu。 然后我得到了

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不提供url作为wlsview的参数。它将带有文件的路径传递给浏览器。例如

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

具有实际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>

创建一个带有内容的文件jupyter-notebook-browser,以提取实际的url

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

然后运行jupyter-notebook --browser=jupyter-notebook-browser

或者定义BROWSER变量并运行

export BROWSER="jupyter-notebook-browser"
jupyter-notebook

启动笔记本时手动分配不同的端口号。例如:

jupyter notebook --port=8889

相关问题 更多 >