anaconda jupyter notebook启动不了报错, application notebook may have produced errors,Traceback...
环境:
windows11 + anaconda + jupyter notebook + vscode
问题描述:
anaconda可以正常打开,environment正常,anaconda cmd正常,下载安装包之类的也没问题。
vscode可以访问 jupyter notebook之前创建的目录,可以使用anaconda的python kernel进行编译运行。
从anaconda尝试打开 jupyter notebook时会报错
在anaconda cmd中尝试jupyter notebook --generate-config
,会报错
报错内容:
application notebook may have produced errors
traceback …
(后面应该是python或者anaconda/lib路径下的一些py文件里面的报错,显示某个函数的参数不存在)
原因
更改了默认浏览器(我从Microsoft edge 改成了 chrome),jupyter notebook还根据默认配置路径找可执行程序,当然会报错
解决办法
- 关闭anaconda和jupyter notebook
- cmd中依次运行
pip uninstall traitlets
pip install traitlets
pip install update
- 打开anaconda,然后打开CMD.exe Prompt,在里面输入
jupyter notebook --generate-config
。会返回给你一个地址,这就是配置文件jupyter_notebook_config.py的地址(比如我的就是C:\Users\flash\.jupyter\jupyter_notebook_config.py
)。用你习惯的文本编辑器打开配置文件 - 在配置文件中找到
NotebookApp.browser
,配置文件代码如下:
## Specify what command to use to invoke a web
# browser when opening the notebook. If not specified, the
# default browser will be determined by the `webbrowser`
# standard library module, which allows setting of the
# BROWSER environment variable to override it.
# Default: ''
# c.NotebookApp.browser = ''
# 在这里加入你的配置
在图示位置插入如下代码
import webbrowser
webbrowser.register("chrome",None,webbrowser.GenericBrowser(u"你的浏览器可执行程序文件地址"))
c.NotebookApp.browser = 'chrome'
字符串的内容应该是,你想更换的浏览器的可执行文件位置,比如我想换成默认用chrome启动jupyter notebook,那么我找到电脑中chrome可执行文件在C:\Program Files\Google\Chrome\Application\chrome.exe
,就把这段换成GenericBrowser(u"C:\Program Files\Google\Chrome\Application\\chrome.exe")
,整体应当如下:
# Default: ''
# c.NotebookApp.browser = ''
import webbrowser
webbrowser.register("chrome",None,webbrowser.GenericBrowser(u"C:\Program Files\Google\Chrome\Application\\chrome.exe"))
c.NotebookApp.browser = 'chrome'
注意
请根据实际情况来复制浏览器地址,哪怕你也打算更换成chrome,你的地址也可能会不一样,比如Program Files或Program Files(x86)的情况。更换其他浏览器同理,请自行寻找对应的地址。