基本上是因为jupyter notebook的kernel所用的python和命令提示符中的python环境不一样。
首先分别在cmd和jupyter notebook下查看所用python版本:
import sys sys.executable
如果不一样的话就进行下一步,更改jupyter notebook的kernel环境:
在命令行输入:
ipython kernelspec list
可以看到指定kernel地址的文件夹 :
Available kernels: python2 C:UsersadriannaAppDataRoamingjupyterkernelspython2 python3 C:UsersadriannaAppDataRoamingjupyterkernelspython3
打开kernel.json 文件 ,将其中的python地址换成cmd中的python地址。
代码语言:javascript复制{
"display_name": "Python 2",
"language": "python",
"argv": [
"D:Anaconda2python.exe",
"-m",
"ipykernel",
"-f",
"{connection_file}"
]
}
补充知识:jupyter 安装后无法在mac terminal启动
系统:macOS Catalina
用pip3安装了jupyter
$ pip3 install jupyterlab
但是,但在terminal中输入
$ jupyter notebook
提示无法找到命令。
这是怎么回事呢???
系统环境变量的问题,也就是没有添加jupyter所在目录到系统环境中。
这里我只讲下我是如何快速解决的。
首先:找jupyter安装在哪
打开terminal,输入python3回车
$ python3 Python 3.7.2 (v3.7.2:9a3ffc0492, Dec 24 2018, 02:44:43) [Clang 6.0 (clang-600.0.57)] on darwin Type “help”, “copyright”, “credits” or “license” for more information.
导入sysmodule
import sys
打印sys.path
print(sys.path)
输出结果如下:
[”, ‘/Library/Frameworks/Python.framework/Versions/3.7/lib/python37.zip’, ‘/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7’, ‘/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload’, ‘/Users/mac/Library/Python/3.7/lib/python/site-packages’, ‘/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages’, ‘/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/setuptools-40.8.0-py3.7.egg’, ‘/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip-19.0.3-py3.7.egg’, ‘/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/incremental-17.5.0-py3.7.egg’, ‘/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/Twisted-18.9.0-py3.7-macosx-10.9-x86_64.egg’]
jupyter就安装在这个目录:/Library/Frameworks/Python.framework/Versions/3.7/bin/jupyter
创建个软链接到/usr/local/bin/
$ ln -s /Library/Frameworks/Python.framework/Versions/3.7/bin/jupyter /usr/local/bin/jupyter
打开terminal输入:
$ jupyter notebook
成功!!!
以上这篇解决jupyter notebook import error但是命令提示符import正常的问题就是小编分享给大家的全部内容了,希望能给大家一个参考。