在尝试在 Python 3.7 上启动 Jupyter 时,我观察到以下情况:
$ jupyter notebook
Traceback (most recent call last):
File "/usr/local/bin/jupyter-notebook", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python3.7/dist-packages/jupyter_core/application.py", line 266, in launch_instance
return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/traitlets/config/application.py", line 657, in launch_instance
app.initialize(argv)
File "<decorator-gen-7>", line 2, in initialize
File "/usr/local/lib/python3.7/dist-packages/traitlets/config/application.py", line 87, in catch_config_error
return method(app, *args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/notebook/notebookapp.py", line 1629, in initialize
self.init_webapp()
File "/usr/local/lib/python3.7/dist-packages/notebook/notebookapp.py", line 1379, in init_webapp
self.jinja_environment_options,
File "/usr/local/lib/python3.7/dist-packages/notebook/notebookapp.py", line 158, in __init__
default_url, settings_overrides, jinja_env_options)
File "/usr/local/lib/python3.7/dist-packages/notebook/notebookapp.py", line 270, in init_settings
nbextensions_path=jupyter_app.nbextensions_path,
File "/usr/local/lib/python3.7/dist-packages/notebook/notebookapp.py", line 1066, in nbextensions_path
from IPython.paths import get_ipython_dir
File "/usr/local/lib/python3.7/dist-packages/IPython/__init__.py", line 54, in <module>
from .core.application import Application
File "/usr/local/lib/python3.7/dist-packages/IPython/core/application.py", line 25, in <module>
from IPython.core import release, crashhandler
File "/usr/local/lib/python3.7/dist-packages/IPython/core/crashhandler.py", line 27, in <module>
from IPython.core import ultratb
File "/usr/local/lib/python3.7/dist-packages/IPython/core/ultratb.py", line 119, in <module>
from IPython.utils import path as util_path
File "/usr/local/lib/python3.7/dist-packages/IPython/utils/path.py", line 17, in <module>
from IPython.utils.process import system
File "/usr/local/lib/python3.7/dist-packages/IPython/utils/process.py", line 19, in <module>
from ._process_posix import system, getoutput, arg_split, check_pid
File "/usr/local/lib/python3.7/dist-packages/IPython/utils/_process_posix.py", line 23, in <module>
import pexpect
File "/usr/lib/python3/dist-packages/pexpect/__init__.py", line 75, in <module>
from .pty_spawn import spawn, spawnu
File "/usr/lib/python3/dist-packages/pexpect/pty_spawn.py", line 15, in <module>
from .spawnbase import SpawnBase
File "/usr/lib/python3/dist-packages/pexpect/spawnbase.py", line 218
def expect(self, pattern, timeout=-1, searchwindowsize=-1, async=False):
^
SyntaxError: invalid syntax
我已经安装python3.7-distutils
(似乎是 feature pexpect
)并且我已经使用 重新安装了 Jupyter pip3
,但我仍然看到这个错误。我还卸载并重新安装了以下软件包:
python3.7 python3.7-dev python3.7-distutils python3.7-tk
应该做什么?
我看到对此修复程序的引用,但假设它是一个修复程序,不知道如何在此 16.04 LTS 安装上启动并运行它。
编辑:在 Python 3.7 中导入pexpect
时,我得到了同样的结果:
>>> import pexpect
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/pexpect/__init__.py", line 75, in <module>
from .pty_spawn import spawn, spawnu
File "/usr/lib/python3/dist-packages/pexpect/pty_spawn.py", line 15, in <module>
from .spawnbase import SpawnBase
File "/usr/lib/python3/dist-packages/pexpect/spawnbase.py", line 218
def expect(self, pattern, timeout=-1, searchwindowsize=-1, async=False):
^
SyntaxError: invalid syntax
对我来说,它与 apt-get installed python3 冲突,所以我必须先卸载它/它们:
sudo apt-get remove python-pexpect python3-pexpect
接着
sudo pip3.7 install --upgrade pexpect
从https://github.com/pexpect/pexpect/releases/tag/4.6下载 pexpect4.6 源代码
提取源代码,进入文件夹并通过以下方式安装 pexpect:
sudo python3.7 setup.py install
这应该可以解决您的问题。:)
我遇到了同样的问题,以下步骤对我有用。
我去了 /usrlib/python3/dist-packages/pexpect/ 那里我
希望它也对其他人有所帮助。
我遇到了同样的错误。我试图:
我得到了:
之后我尝试了:
现在 jupyter 工作得很好。
我在运行 django 测试时遇到了这个问题。将版本升级到当时的最新版本(4.8),修复了问题。