简体   繁体   English

无法直接在 Mac 上的终端中运行 Jupyter notebook

[英]Cannot run Jupyter notebook directly in the terminal on Mac

I want to run jupyter notebook on my mac using jupyter notebook in the terminal, but if I run this code, it gives me an error:我想在终端中使用jupyter notebook在我的 mac 上运行 jupyter notebook,但是如果我运行这段代码,它会给我一个错误:

vlan-2625-10-16-106-253:~ brandon$ jupyter notebook
Traceback (most recent call last):
  File "/usr/local/bin/jupyter-notebook", line 5, in <module>
    from notebook.notebookapp import main
ModuleNotFoundError: No module named 'notebook'

But if I use /usr/local/bin/python3.7 -m jupyter notebook , then it works.但是如果我使用/usr/local/bin/python3.7 -m jupyter notebook ,那么它可以工作。

I know maybe it's because I have several versions of python on my computer, or it's because the path of jupyter is incorrect, but I don't know how to deal with it.我知道可能是因为我的电脑上有几个版本的python,或者是因为jupyter的路径不正确,但我不知道如何处理。

vlan-2625-10-16-106-253:~ brandon$ which jupyter
/usr/local/bin/jupyter
vlan-2625-10-16-106-253:~ brandon$ which python3
/usr/local/bin/python3

If I tried to uninstall jupyter by brew uninstall jupyter or pip3 uninstall jupyter and then pip3 install jupyter , it still doesn't work.如果我尝试通过brew uninstall jupyterpip3 uninstall jupyter然后pip3 install jupyter ,它仍然无法正常工作。

If I install jupyter again, it shows:如果我再次安装 jupyter,它会显示:

vlan-2625-10-16-106-253:~ brandon$ pip3 install jupyter
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: jupyter in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (1.0.0)
Requirement already satisfied: notebook in ./Library/Python/3.7/lib/python/site-packages (from jupyter) (6.3.0)
Requirement already satisfied: nbconvert in ./Library/Python/3.7/lib/python/site-packages (from jupyter) (5.6.1)
Requirement already satisfied: qtconsole in ./Library/Python/3.7/lib/python/site-packages (from jupyter) (4.7.6)
Requirement already satisfied: ipykernel in ./Library/Python/3.7/lib/python/site-packages (from jupyter) (5.3.4)
Requirement already satisfied: jupyter-console in ./Library/Python/3.7/lib/python/site-packages (from jupyter) (6.2.0)
Requirement already satisfied: ipywidgets in ./Library/Python/3.7/lib/python/site-packages (from jupyter) (7.5.1)
Requirement already satisfied: jupyter-client in ./Library/Python/3.7/lib/python/site-packages (from ipykernel->jupyter) (6.1.7)
Requirement already satisfied: traitlets>=4.1.0 in ./Library/Python/3.7/lib/python/site-packages (from ipykernel->jupyter) (5.0.0)
Requirement already satisfied: ipython>=5.0.0 in ./Library/Python/3.7/lib/python/site-packages (from ipykernel->jupyter) (7.18.1)
Requirement already satisfied: appnope in ./Library/Python/3.7/lib/python/site-packages (from ipykernel->jupyter) (0.1.0)
Requirement already satisfied: tornado>=4.2 in ./Library/Python/3.7/lib/python/site-packages (from ipykernel->jupyter) (6.1)
Requirement already satisfied: pexpect>4.3 in ./Library/Python/3.7/lib/python/site-packages (from ipython>=5.0.0->ipykernel->jupyter) (4.8.0)
Requirement already satisfied: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in ./Library/Python/3.7/lib/python/site-packages (from ipython>=5.0.0->ipykernel->jupyter) (3.0.7)
Requirement already satisfied: backcall in ./Library/Python/3.7/lib/python/site-packages (from ipython>=5.0.0->ipykernel->jupyter) (0.2.0)
Requirement already satisfied: pickleshare in ./Library/Python/3.7/lib/python/site-packages (from ipython>=5.0.0->ipykernel->jupyter) (0.7.5)
Requirement already satisfied: setuptools>=18.5 in ./Library/Python/3.7/lib/python/site-packages (from ipython>=5.0.0->ipykernel->jupyter) (49.2.0)
Requirement already satisfied: jedi>=0.10 in ./Library/Python/3.7/lib/python/site-packages (from ipython>=5.0.0->ipykernel->jupyter) (0.17.2)
Requirement already satisfied: decorator in ./Library/Python/3.7/lib/python/site-packages (from ipython>=5.0.0->ipykernel->jupyter) (4.4.2)
Requirement already satisfied: pygments in ./Library/Python/3.7/lib/python/site-packages (from ipython>=5.0.0->ipykernel->jupyter) (2.6.1)
Requirement already satisfied: parso<0.8.0,>=0.7.0 in ./Library/Python/3.7/lib/python/site-packages (from jedi>=0.10->ipython>=5.0.0->ipykernel->jupyter) (0.7.1)
Requirement already satisfied: ptyprocess>=0.5 in ./Library/Python/3.7/lib/python/site-packages (from pexpect>4.3->ipython>=5.0.0->ipykernel->jupyter) (0.6.0)
Requirement already satisfied: wcwidth in ./Library/Python/3.7/lib/python/site-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->ipython>=5.0.0->ipykernel->jupyter) (0.2.5)
Requirement already satisfied: ipython-genutils in ./Library/Python/3.7/lib/python/site-packages (from traitlets>=4.1.0->ipykernel->jupyter) (0.2.0)
Requirement already satisfied: widgetsnbextension~=3.5.0 in ./Library/Python/3.7/lib/python/site-packages (from ipywidgets->jupyter) (3.5.1)
Requirement already satisfied: nbformat>=4.2.0 in ./Library/Python/3.7/lib/python/site-packages (from ipywidgets->jupyter) (5.0.7)
Requirement already satisfied: jupyter-core in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from nbformat>=4.2.0->ipywidgets->jupyter) (4.7.1)
Requirement already satisfied: jsonschema!=2.5.0,>=2.4 in ./Library/Python/3.7/lib/python/site-packages (from nbformat>=4.2.0->ipywidgets->jupyter) (3.2.0)
Requirement already satisfied: pyrsistent>=0.14.0 in ./Library/Python/3.7/lib/python/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat>=4.2.0->ipywidgets->jupyter) (0.16.0)
Requirement already satisfied: six>=1.11.0 in ./Library/Python/3.7/lib/python/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat>=4.2.0->ipywidgets->jupyter) (1.15.0)
Requirement already satisfied: attrs>=17.4.0 in ./Library/Python/3.7/lib/python/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat>=4.2.0->ipywidgets->jupyter) (20.1.0)
Requirement already satisfied: importlib-metadata in ./Library/Python/3.7/lib/python/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat>=4.2.0->ipywidgets->jupyter) (1.7.0)
Requirement already satisfied: terminado>=0.8.3 in ./Library/Python/3.7/lib/python/site-packages (from notebook->jupyter) (0.8.3)
Requirement already satisfied: Send2Trash>=1.5.0 in ./Library/Python/3.7/lib/python/site-packages (from notebook->jupyter) (1.5.0)
Requirement already satisfied: jinja2 in ./Library/Python/3.7/lib/python/site-packages (from notebook->jupyter) (2.11.2)
Requirement already satisfied: pyzmq>=17 in ./Library/Python/3.7/lib/python/site-packages (from notebook->jupyter) (22.0.3)
Requirement already satisfied: prometheus-client in ./Library/Python/3.7/lib/python/site-packages (from notebook->jupyter) (0.8.0)
Requirement already satisfied: argon2-cffi in ./Library/Python/3.7/lib/python/site-packages (from notebook->jupyter) (20.1.0)
Requirement already satisfied: python-dateutil>=2.1 in ./Library/Python/3.7/lib/python/site-packages (from jupyter-client->ipykernel->jupyter) (2.8.1)
Requirement already satisfied: cffi>=1.0.0 in ./Library/Python/3.7/lib/python/site-packages (from argon2-cffi->notebook->jupyter) (1.14.2)
Requirement already satisfied: pycparser in ./Library/Python/3.7/lib/python/site-packages (from cffi>=1.0.0->argon2-cffi->notebook->jupyter) (2.20)
Requirement already satisfied: zipp>=0.5 in ./Library/Python/3.7/lib/python/site-packages (from importlib-metadata->jsonschema!=2.5.0,>=2.4->nbformat>=4.2.0->ipywidgets->jupyter) (3.1.0)
Requirement already satisfied: MarkupSafe>=0.23 in ./Library/Python/3.7/lib/python/site-packages (from jinja2->notebook->jupyter) (1.1.1)
Requirement already satisfied: entrypoints>=0.2.2 in ./Library/Python/3.7/lib/python/site-packages (from nbconvert->jupyter) (0.3)
Requirement already satisfied: mistune<2,>=0.8.1 in ./Library/Python/3.7/lib/python/site-packages (from nbconvert->jupyter) (0.8.4)
Requirement already satisfied: pandocfilters>=1.4.1 in ./Library/Python/3.7/lib/python/site-packages (from nbconvert->jupyter) (1.4.2)
Requirement already satisfied: testpath in ./Library/Python/3.7/lib/python/site-packages (from nbconvert->jupyter) (0.4.4)
Requirement already satisfied: defusedxml in ./Library/Python/3.7/lib/python/site-packages (from nbconvert->jupyter) (0.6.0)
Requirement already satisfied: bleach in ./Library/Python/3.7/lib/python/site-packages (from nbconvert->jupyter) (3.1.5)
Requirement already satisfied: packaging in ./Library/Python/3.7/lib/python/site-packages (from bleach->nbconvert->jupyter) (20.4)
Requirement already satisfied: webencodings in ./Library/Python/3.7/lib/python/site-packages (from bleach->nbconvert->jupyter) (0.5.1)
Requirement already satisfied: pyparsing>=2.0.2 in ./Library/Python/3.7/lib/python/site-packages (from packaging->bleach->nbconvert->jupyter) (2.4.7)
Requirement already satisfied: qtpy in ./Library/Python/3.7/lib/python/site-packages (from qtconsole->jupyter) (1.9.0)

If I want to run.ipynb file in pyCharm, I also receive the same error:如果我想在 pyCharm 中运行.ipynb 文件,我也会收到同样的错误: 在此处输入图像描述

I think it's the same problem as I cannot directly run jupyter notebook in the terminal.我认为这是同样的问题,因为我无法在终端中直接运行jupyter notebook This problem has been bothering me a lot and i searched a lot but I still can't figure it out.这个问题一直困扰着我很多,我搜索了很多,但我仍然无法弄清楚。 I wonder if I can change the path of jupyter command?我想知道我是否可以更改jupyter命令的路径? It would be helpful if someone can answer this.如果有人能回答这个问题会很有帮助。

Thanks in advance!提前致谢!

you can check if python.exe is added on path.Environment Variables >>> System variables >>> path.(This is for windows) but i think there should be sth similar.您可以检查 python.exe 是否已添加到 path.Environment Variables >>> System variables >>> path.(这是用于 Windows)但我认为应该有类似的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM