【问题标题】:Cannot run jupyter notebook by python2.7python2.7无法运行jupyter notebook
【发布时间】:2021-10-29 19:01:40
【问题描述】:

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 是不可能的吗?

【问题讨论】:

    标签: python-2.7 jupyter-notebook anaconda


    【解决方案1】:

    我遇到了同样的问题。

        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-5.1.0,我猜它是由 conda 使用 jupyter 自动安装的)需要 Python>=3.5,而我有 python 2.7。

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

    pip uninstall decorator
    

    成功卸载 decorator-5.1.0

    pip install decorator
    

    成功安装decorator-4.4.2

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-21
      • 2020-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-07
      相关资源
      最近更新 更多