无法通过Python2.7运行Jupyter Notebook。

5

MacBook笔记本电脑

在终端中激活了py27。当我尝试运行 jupyter notebook 时,它返回:

bash-3.2$ source activate py27
(py27) bash-3.2$ jupyter notebook
Traceback (most recent call last):
  File "/Users/xx/anaconda3/envs/py27/bin/jupyter-notebook", line 7, in <module>
    from notebook.notebookapp import main
  File "/Users/xx/anaconda3/envs/py27/lib/python2.7/site-packages/notebook/__init__.py", line 25, in <module>
    from .nbextensions import install_nbextension
  File "/Users/xx/anaconda3/envs/py27/lib/python2.7/site-packages/notebook/nbextensions.py", line 31, in <module>
    from .config_manager import BaseJSONConfigManager
  File "/Users/xx/anaconda3/envs/py27/lib/python2.7/site-packages/notebook/config_manager.py", line 15, in <module>
    from traitlets.config import LoggingConfigurable
  File "/Users/xx/anaconda3/envs/py27/lib/python2.7/site-packages/traitlets/config/__init__.py", line 6, in <module>
    from .application import *
  File "/Users/xx/anaconda3/envs/py27/lib/python2.7/site-packages/traitlets/config/application.py", line 17, in <module>
    from decorator import decorator
  File "/Users/xx/anaconda3/envs/py27/lib/python2.7/site-packages/decorator.py", line 162
    print('Error in generated code:', file=sys.stderr)
                                          ^
SyntaxError: invalid syntax
(py27) bash-3.2$

如何解决这个问题?现在在Jupyter中运行Python 2.7是不可能的吗?

一样的情况。看起来conda拉取了一些依赖项的py3版本。 - Claudio
4
我找到了一个解决方法: conda install decorator=4.4.0 - Claudio
在Ubuntu Linux和最近的M1处理器的Mac上遇到了相同的错误。 Python版本为2.7.18,并尝试了几乎所有可用的jupyter软件包版本。 但是Claudio的解决方法解决了这个问题! - PierreE
另一个被证明是必要的软件包: conda install functools_lru_cache - PierreE
1个回答

6

我有同样的问题。

    from decorator import decorator
  File "/home/hamza/miniconda3/envs/py27/lib/python2.7/site-packages/decorator.py", line 162
    print('Error in generated code:', file=sys.stderr)
                                          ^
SyntaxError: invalid syntax

我发现已安装的“decorator”版本(在我的情况下为decorator-5.1.0,我猜它是由conda自动安装到jupyter中的)需要Python>=3.5,而我只有python 2.7。

我所做的仅仅是重新安装decorator包以适配py27:

pip uninstall decorator

成功卸载了decorator-5.1.0。
pip install decorator

成功安装了 decorator-4.4.2


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接