无法通过python2.7运行jupyter笔记本

gar*_*ach 5 python-2.7 anaconda jupyter-notebook

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$
Run Code Online (Sandbox Code Playgroud)

怎么解决这个问题呢?现在无法在 Jupyter 中运行 python 2.7 吗?

小智 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
Run Code Online (Sandbox Code Playgroud)

我发现安装的“decorator”版本(在我的例子中decorator-5.1.0,我猜它是由conda使用jupyter自动安装的)需要Python>=3.5,而我有python 2.7。

我所做的就是重新安装装饰器包以适合 py27:

pip uninstall decorator
Run Code Online (Sandbox Code Playgroud)

成功卸载decorator-5.1.0

pip install decorator
Run Code Online (Sandbox Code Playgroud)

成功安装decorator-4.4.2