解决jupyter notebook import error但是命令提示符import正常的问题
基本上是因为jupyternotebook的kernel所用的python和命令提示符中的python环境不一样。
首先分别在cmd和jupyternotebook下查看所用python版本:
importsys
sys.executable
如果不一样的话就进行下一步,更改jupyternotebook的kernel环境:
在命令行输入:
ipythonkernelspeclist
可以看到指定kernel地址的文件夹:
Availablekernels:
python2C:\Users\adrianna\AppData\Roaming\jupyter\kernels\python2
python3C:\Users\adrianna\AppData\Roaming\jupyter\kernels\python3
打开kernel.json文件,将其中的python地址换成cmd中的python地址。
{ "display_name":"Python2", "language":"python", "argv":[ "D:\\Anaconda2\\python.exe", "-m", "ipykernel", "-f", "{connection_file}" ] }
补充知识:jupyter安装后无法在macterminal启动
系统:macOSCatalina
用pip3安装了jupyter
$pip3installjupyterlab
但是,但在terminal中输入
$jupyternotebook
提示无法找到命令。
这是怎么回事呢???
系统环境变量的问题,也就是没有添加jupyter所在目录到系统环境中。
这里我只讲下我是如何快速解决的。
首先:找jupyter安装在哪
打开terminal,输入python3回车
$python3
Python3.7.2(v3.7.2:9a3ffc0492,Dec242018,02:44:43)
[Clang6.0(clang-600.0.57)]ondarwin
Type"help","copyright","credits"or"license"formoreinformation.
导入sysmodule
>>>importsys
打印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输入:
$jupyternotebook
成功!!!
以上这篇解决jupyternotebookimporterror但是命令提示符import正常的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。