Jupyter启动报错 ImportError: DLL load failed while importing error

命令行启动jupyter报错

使用 cmd,输入 jupyter notebook 后出现报错:

ImportError: DLL load failed while importing error: 找不到指定的模块。
当然先说, 有这个报错的前提是,已经添加了环境变量了。

原因应该是环境问题,本地装有其他版本的Python,而安装 Anaconda 时选择的Python版本和本地的不一致,通过 Powershell 启动启动,下图中有(base),可以发现这里是使用了Python虚拟环境。

解决:

使用 jupyter 的 PowerShell 打开,
请添加图片描述
请添加图片描述
此时,默认的浏览器应该会自动打开 http://localhost:8888/tree,可以发现 jupyter 已经成功启动了。

由于这边 Powershell 使用的 虚拟环境,所以如果不使用 Powershell,直接使用命令行也可,先激活虚拟环境:请添加图片描述


修改jupyter默认位置

使用 jupyter 的 PowerShell,打开并输入 jupyter notebook --generate-config

(base) PS C:\Users\john> jupyter notebook --generate-config
Overwrite C:\Users\john\.jupyter\jupyter_notebook_config.py with default config? [y/N]n
(base) PS C:\Users\john>

可以看到配置路径:C:\Users\john\.jupyter\jupyter_notebook_config.py,进入该文件,修改配置

找到 “The directory to use for notebooks and kernels”,将 “c.NotebookApp.notebook_dir” 解注释,并改成自己想要自定义的路径,比如我的 “D:\CodeTest”:

## The directory to use for notebooks and kernels.
#  Default: ''
c.NotebookApp.notebook_dir = 'D:\CodeTest'

windows 的快捷方式的修改

进入 "Jupyter Notebook (anaconda3)“图标的"属性”-“目标”,将目标中的变量删除("%USERPROFILE%",包含前面的空格),仅剩下文件路径名,例如:

C:\softwares\anaconda3\python.exe C:\softwares\anaconda3\cwp.py C:\softwares\anaconda3 C:\softwares\anaconda3\python.exe C:\softwares\anaconda3\Scripts\jupyter-notebook-script.py

修改好后,启动 jupyter notebook,查看在自定义的路径下,是否有生成文件。


Pycharm 中配置

进入 “File-Settings-Jupyter-Jupyter Servers”,

对于 “Python interpreter”,选择自己本地安装 Anaconda 的位置里的 python.exe,端口可以不改,不过如果想另外在浏览器中开一个 jupyter,可能会都会默认使用 8888 端口。
请添加图片描述

猜你喜欢

转载自blog.csdn.net/qq_31362767/article/details/123649644