我已经在 Ubuntu 18.04 上使用 pip 安装了 Jupyter Notebook。它显然安装正确,因为当我在终端中输入时:
which jupyter
它返回
/usr/local/bin/jupyter
但是当我jupyter notebook
在终端中运行时,它显示以下错误(无论是否带有sudo
):
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 14, in <module>
from .spawnbase import SpawnBase
File "/usr/lib/python3/dist-packages/pexpect/spawnbase.py", line 224
def expect(self, pattern, timeout=-1, searchwindowsize=-1, async=False):
^
SyntaxError: invalid syntax
我正在使用 Python 版本 3.7。如何摆脱此问题?
答案1
好吧,我只安装了 Jupyter Notebook,而没有安装 anaconda。它应该可以工作。但由于一些我不知道的原因,我无法运行它。
因此,正如建议的那样官方页面,我使用 anaconda 安装了 Jupyter,这样做之后,我现在能够使用命令成功运行 Jupyter notebook jupyter notebook
。
尽管现在已经通过其他方式解决了该问题,但我仍然想知道我最初遇到的问题是什么,以及如何解决它。