【问题标题】:Jupyter using the wrong version of pythonJupyter 使用错误版本的 python
【发布时间】:2016-02-22 18:29:43
【问题描述】:

您好,我已经安装了 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

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

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

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

【问题讨论】:

    标签: python python-2.6 jupyter jupyter-notebook


    【解决方案1】:

    这可能是您的 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 版本。

    【讨论】:

    • 这很有帮助。对于 Windows 用户,kernel.json 的路径可能是这样的:C:\Users[username]\AppData\Roaming\jupyter\kernels\pythonX 其中 x 是 python 2 或 3。
    • AppData\Roaming\jupyter 中没有 kernels 文件夹
    【解决方案2】:

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

    【讨论】:

    • 即使在卸载 jupyter 并在 python 3.8 中重新安装后,它仍在尝试启动不存在的 "C:\program files\python37\python.exe"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-07
    • 2020-07-22
    • 2015-01-12
    • 1970-01-01
    • 1970-01-01
    • 2022-11-16
    相关资源
    最近更新 更多