WSL安装Jupyter notebook需要注意的事项

在Windows Linux子系统(WSL)安装Jupyter notebook时,可能会遇到浏览器无法打开或找不到文件、Jupyter notebook超时等待响应等问题。解决方法包括生成并编辑config文件,定义浏览器路径,修改WSL配置,以及正确使用Ctrl+C关闭Jupyter进程,避免使用Ctrl+Z导致的超时问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

WSL安装Jupyter notebook需要注意的事项

常规的Jupyter notebook安装可以参考网上很多资料,这里是由于我的是Windows linux子系统,所以有额外需要注意的东西。记录一下。

打不开浏览器、浏览器找不到文件
先生成config文件,终端输入

jupyter notebook  --generate-config

之后进入./jupyter,打开jupyter_notebook_config.py
输入以下四行,定义好自己要用的浏览器,比如我用的火狐,就这样加,其他浏览器相应地改名字就好了。

import webbrowser
webbrowser.register ('firefox',None,webbrowser.GenericBrowser('...浏览器路径(注意是反斜杠/)/firefox.exe'))
c.NotebookApp.open_browser = True 
c.NotebookApp.browser = 'firefox' 

上面这四行是添加了浏览器,其中后面两行可以直接搜索再对应的位置上更改就好。

接下来在jupyter_notebook_config.py中查找WSL:vim中直接输入/WSL,回车定位,可以找到如下解释:

## Disable launching browser by redirect file
#
#  For versions of notebook > 5.7.2, a security feature measure was added that
#  prevented the authentication token used to launch the browser from being
#  visible. This feature makes it difficult for other users on a multi-user
#  system from running code in your Jupyter session as you.
#
#  However, some environments (like Windows Subsystem for Linux (WSL) and
#  Chromebooks), launching a browser using a redirect file can lead the browser
#  failing to load.  This is because of the difference in file structures/paths
#  between the runtime and  the browser.
#
#  Disabling this setting to False will disable this behavior, allowing the
#  browser  to launch by using a URL and visible token (as before).
#c.NotebookApp.use_redirect_file = True
变成
c.NotebookApp.use_redirect_file = False

我们就按他说的办,把最后一行删掉#,把True改成False。这样浏览器就不会再出现找不到文件的问题了。

打开Jupyter notebook超时,一直等待响应

那有可能你和我的习惯一样,都是用像下面这样Ctrl+z来关闭Jupyter的,这样的话,继续启动就会一直等待响应。
在这里插入图片描述

正确关闭的方法是Ctrl+c:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值