无法将 python3 内核添加到 Jupyter

Cannot add python3 kernel to Jupyter

我想更改 Jupyter 中内核的路径,将其设置为我在机器中使用的路径。

这是在 jupyter 中安装的原始内核:

jupyter kernelspec list

Available kernels:
python3 /home/n/.local/share/jupyter/kernels/python3
python2 /usr/local/share/jupyter/kernels/python2

然后我在我的机器中检查了 python3 的路径,如下所示:

which python3

/usr/bin/python3

$ ipython 内核规范列表

我这样删除了python3的内核:

jupyter kernelspec uninstall python3

成功执行,然后我尝试使用我之前找到的路径安装 python3,如下所示:

jupyter kernelspec install /usr/bin/python3

这给了我这个错误:

File "/usr/local/bin/jupyter-kernelspec", line 11, in sys.exit(KernelSpecApp.launch_instance())
File "/usr/local/lib/python2.7/dist-packages/traitlets/config/application.py", line 658, in launch_instance app.start()
File "/usr/local/lib/python2.7/dist-packages/jupyter_client/kernelspecapp.py", line 273, in start return self.subapp.start()
File "/usr/local/lib/python2.7/dist-packages/jupyter_client/kernelspecapp.py", line 143, in start replace=self.replace,
File "/usr/local/lib/python2.7/dist-packages/jupyter_client/kernelspec.py", line 299, in install_kernel_spec shutil.copytree(source_dir, destination)
File "/usr/lib/python2.7/shutil.py", line 171, in copytree

names = os.listdir(src) OSError: [Errno 20] Not a directory: '/usr/bin/python3'

然后我寻找正确的路径是这样的:

python3 -c "import sys; print ('\n'.join(sys.path))"

/usr/lib/python3.4

/usr/lib/python3.4/plat-x86_64-linux-gnu

/usr/lib/python3.4/lib-dynload

/usr/local/lib/python3.4/dist-packages

/usr/local/lib/python3.4/dist-packages/setuptools-28.8.0-py3.4.egg

/usr/lib/python3/dist-packages

我试过这样安装它:

sudo jupyter kernelspec install /usr/lib/python3.4

[InstallKernelSpec] Installed kernelspec python3.4 in /usr/local/share/jupyter/kernels/python3.4

现在,当我启动 jupyter 时,根本没有 Python 3 作为内核,我现在不确定该怎么办?

您可能没有在 python 3 安装中安装 ipykernel。要安装 python 内核,正确的步骤是:

pip3 install ipykernel

python3 -m ipykernel install --user

here

我可以通过使用 anaconda 重新安装 python3 来解决问题,anaconda 随附在其包中的 Jupyter 中。

您可以按照此处的命令安装anaconda: https://conda.io/docs/user-guide/install/linux.html