无法在 jupyter notebook 上启动内核

Failed to start the kernel on jupyter notebook

我通过 Homebrew 安装了 python 版本 3.6.5_13.7.0
jupyter 需要 python3.6 才能启动。如果我切换到 python3.7.

它不会启动

启动后,启动内核失败。出现此错误:

Traceback (most recent call last):
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/vendor/lib/python3.6/site-packages/tornado/web.py", line 1543, in _execute
result = yield result
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/vendor/lib/python3.6/site-packages/tornado/gen.py", line 1099, in run
value = future.result()
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/vendor/lib/python3.6/site-packages/tornado/gen.py", line 1107, in run
yielded = self.gen.throw(*exc_info)
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/lib/python3.6/site-packages/notebook/services/sessions/handlers.py", line 73, in post
type=mtype))
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/vendor/lib/python3.6/site-packages/tornado/gen.py", line 1099, in run
value = future.result()
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/vendor/lib/python3.6/site-packages/tornado/gen.py", line 1107, in run
yielded = self.gen.throw(*exc_info)
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/lib/python3.6/site-packages/notebook/services/sessions/sessionmanager.py", line 79, in create_session
kernel_id = yield self.start_kernel_for_session(session_id, path, name, type, kernel_name)
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/vendor/lib/python3.6/site-packages/tornado/gen.py", line 1099, in run
value = future.result()
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/vendor/lib/python3.6/site-packages/tornado/gen.py", line 1107, in run
yielded = self.gen.throw(*exc_info)
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/lib/python3.6/site-packages/notebook/services/sessions/sessionmanager.py", line 92, in start_kernel_for_session
self.kernel_manager.start_kernel(path=kernel_path, kernel_name=kernel_name)
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/vendor/lib/python3.6/site-packages/tornado/gen.py", line 1099, in run
value = future.result()
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/vendor/lib/python3.6/site-packages/tornado/gen.py", line 315, in wrapper
yielded = next(result)
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/lib/python3.6/site-packages/notebook/services/kernels/kernelmanager.py", line 148, in start_kernel
super(MappingKernelManager, self).start_kernel(**kwargs)
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/lib/python3.6/site-packages/jupyter_client/multikernelmanager.py", line 110, in start_kernel
km.start_kernel(**kwargs)
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/lib/python3.6/site-packages/jupyter_client/manager.py", line 259, in start_kernel
**kw)
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/lib/python3.6/site-packages/jupyter_client/manager.py", line 204, in _launch_kernel
return launch_kernel(kernel_cmd, **kw)
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/lib/python3.6/site-packages/jupyter_client/launcher.py", line 128, in launch_kernel
proc = Popen(cmd, **kwargs)
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/opt/python/bin/python3.7': '/usr/local/opt/python/bin/python3.7'

据我了解,内核正在寻找 python3.7。我的内核列表只有 python3

$jupyter kernelspec list  
Available kernels:  
python3    /usr/local/etc/jupyter/kernels/python3  

我查看了 this link on github,但没有帮助。如何在相同的 python 版本上制作 jupyter 和内核 运行?

检查内核规格:

$jupyter kernelspec list

这将向您显示可用的内核。在这种情况下:

python3    /usr/local/etc/jupyter/kernels/python3  

打开该目录下的kernel.json文件,在argv键中指定你希望内核使用的python路径。

万一阅读本文的任何人在 Anaconda 中运行 Jupyter Notebook 并遇到相同的错误:

我通过在命令提示符(不是 anaconda 提示符)中使用 pip 安装 Jupyter 找到了解决方法:

$pip install jupyter

然后使用已知方式启动 Jupyter

$cd 'DirectoryofyourNotebook'
$jupyter notebook

更新 jupyter 笔记本解决了我的问题。 但请记住,使用命令行更新它。不是 Anaconda Navigator

pip install -U jupyter

我遇到了同样的问题 - 尝试了以上所有方法均未成功。

上下文:在那台机器上使用 Windows 几年了。我将这台机器用作“需要时随时随地编写代码”的笔记本电脑,并且在 installing/upgrading python 版本或库或环境时不是很小心也不一致。

我的修复 - 不知何故包含 f2py.exe 的文件夹(Numpy - Pandas 建立在其上)不在路径中并且位于以“\Scripts”结尾的隐藏文件夹中。 Python 本身在环境变量中很好。它们位于非常不同的文件夹中 - 而通常它们应该位于文件夹树中的紧密分支中。在环境变量中添加以“\Scripts”结尾且具有 f2py.exe 的文件夹的完整路径为我解决了内核问题。

第 2 步命令:

conda activate <location of your env folder>

第 3 步命令:

python -m ipykernel install --user

有效!