运行jupyter notebook --allow-root后无法连接localhost:8888求助
解决Jupyter Notebook无法在Firefox访问的问题
问题场景
运行命令 jupyter notebook --allow-root 后,Firefox提示无法连接到localhost:8888服务器,提示站点可能暂时不可用、需检查网络或防火墙设置,但Jupyter Notebook运行日志显示服务正常启动:
[I 07:27:27.681 NotebookApp] interrupted
Serving notebooks from local directory: /home/dsm/alx
0 active kernels
Jupyter Notebook 6.5.2 is running at:
http://localhost:8888/?token=24aa9fc8b381e38bce8482e2dcc88414fa94a2eec29f3799
or http://127.0.0.1:8888/?token=24aa9fc8b381e38bce8482e2dcc88414fa94a2eec29f3799
解决步骤
- 直接复制完整链接访问:把日志里带token的完整地址(比如
http://127.0.0.1:8888/?token=24aa9fc8b381e38bce8482e2dcc88414fa94a2eec29f3799)直接粘贴到Firefox地址栏,避免手动输入时错漏token或端口。 - 检查本地回环网络:在终端运行
ping 127.0.0.1,如果没有丢包说明本地回环正常;若丢包,需排查系统回环接口配置。 - 临时关闭防火墙测试:Linux下根据防火墙类型执行命令,比如
sudo systemctl stop firewalld(firewalld环境)或sudo ufw disable(ufw环境),关闭后重新访问。能连上的话,给8888端口添加防火墙规则:sudo ufw allow 8888。 - 修改Jupyter绑定地址:启动时指定绑定所有地址,命令改为
jupyter notebook --allow-root --ip=0.0.0.0,之后用http://127.0.0.1:8888/?token=xxx访问;也可以生成配置文件jupyter notebook --generate-config,打开~/.jupyter/jupyter_notebook_config.py,将c.NotebookApp.ip设置为c.NotebookApp.ip = '0.0.0.0',保存后重启Jupyter。 - 检查Firefox代理设置:打开Firefox设置→网络设置,确保选择“使用系统代理设置”或“不使用代理”,避免代理拦截localhost请求。
- 排查端口占用:运行
lsof -i :8888或netstat -tulpn | grep 8888,查看8888端口是否被其他程序占用。如果被占用,要么杀掉占用进程,要么指定Jupyter用其他端口启动:jupyter notebook --allow-root --port=8889,再访问对应端口。
内容的提问来源于stack exchange,提问作者DANIEL MUTHAMA
相关产品推荐
相关产品推荐

