pip安装jupyter后找不到jupyter

5

尝试了多种方法来安装jupyter,但似乎都没有成功。

可能与MacOS有关,因为最近我遇到了很多MacOS系统的Python问题。

pip install jupyter --user

看起来已经成功安装。

但是却无法找到jupyter。

where jupyter jupyter not found

尝试在SO上找到另一种安装方法。

pip install --upgrade notebook

看起来也已经成功安装。

但是jupyter仍然无法找到。

where pip /usr/local/bin/pip

我应该怎么办才能使命令行中的jupyter notebook命令像这个链接中的第一步那样正常工作:https://jupyter.readthedocs.io/en/latest/running.html#running


你是如何并且在哪里调用jupyter笔记本的?如果我没记错的话,你需要在存放笔记本的目录下才能调用它。 - sheplu
4个回答

6

简短回答: 使用python -m notebook

更新到Catalina操作系统后,我安装了Homebrew的Python: brew install python。 它为Python3添加符号链接,但未添加python命令,因此我将以下内容添加到$PATH变量中:

/usr/local/opt/python/libexec/bin

让brew python成为默认的python命令(不使用系统python,现在python2.7已被弃用)。python -m pip install jupyter是有效的,我可以在~/Library/Python/3.7/bin/中找到jupyter文件,但教程中的jupyter notebook命令不起作用。我只需运行python -m notebook


1
这个有效!谢谢。这应该是被接受的答案。 - llamaro25

2
你需要将本地Python安装目录添加到路径中。显然,在MacOS上默认情况下不会这样做。
尝试执行以下操作:
export PATH="$HOME/Library/Python/<version number>/bin:$PATH"

将其添加到您的~/.bashrc文件中,或者加入它。

2

我的MacOS自带Python 2.7,我使用brew安装了Python3,然后以下命令适用于我:

brew install python3

brew link --overwrite python

pip3 install ipython

python3 -m pip install jupyter


0

尝试使用Conda或Poetry解决此问题。

Poetry使得管理Python依赖项(包括Jupyter)和构建虚拟环境变得更加容易。

以下是将Jupyter添加到项目中的步骤:

  • 运行poetry add pandas jupyter ipykernel以添加依赖项
  • 运行poetry shell在虚拟环境中创建一个shell
  • 运行jupyter notebook启动一个带有所有虚拟环境依赖项访问权限的notebook

其他建议的解决方案只是权宜之计。 Conda / Poetry可以为您提供可持续的解决方案,易于维护,并且可以使您免受不断的Python依赖关系困扰。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接