Jupyter 使用了错误版本的 python

Jupyter using the wrong version of python

您好,我安装了 python 2.7,但没有删除 2.6。我已经在路径中添加了 2.7 并且还作为别名但是当我做 jupyter notebook 时它似乎试图访问 2.6

> jupyter notebook
Traceback (most recent call last):
File "jupyter-notebook", line 7, in <module>
 from notebook.notebookapp import main
 File "/usr/lib/python2.6/site-packages/notebook/__init__.py", line 25, in <module>
from .nbextensions import install_nbextension
File "/usr/lib/python2.6/site-packages/notebook/nbextensions.py", line 226, in  <module>
from traitlets import Bool, Enum, Unicode
File "/usr/lib/python2.6/site-packages/traitlets/__init__.py", line 1, in <module>
from .traitlets import *
File "/usr/lib/python2.6/site-packages/traitlets/traitlets.py", line 1291
return {n: t for (n, t) in cls.class_traits(**metadata).items()
               ^

我的python版本好像指向2.7

$ python --version
Python 2.7.6

以及我的 python 似乎给出了正确的输出:

$ which python
alias python='/usr/local/bin/python2.7'
/usr/local/bin/python2.7

我为 python 的两个版本都安装了 pip。我不确定如何解决这个问题:(

您似乎安装了 jupyter 作为 /usr/lib/python2.6 的扩展。如果是这样,您必须卸载 jupyter 并重新安装到您想要的 python.

可能是您的 python kernel.json 配置有问题。例如我的 python 内核位于:

/usr/local/share/jupyter/kernels/python/kernel.json

并包含:

    {
     "language": "python",
     "display_name": "Python 2.7",
     "argv": [
      "/usr/local/bin/python2.7",
      "-m",
      "ipykernel",
      "-f",
      "{connection_file}"
     ]
    }

确保 argv 部分中的路径指向 python 的正确版本。