使用 pip 或 pip3 在 Anaconda、Python、Jupyter 中安装软件包

Using pip or pip3 to install packages in Anaconda, Python, Jupyter

我一直相信 pip 管理 python2 的包,pip3 管理 python 的包 3. 在 JupyterHub 服务器上,我 运行,我有安装我们团队使用的包的习惯。做 sudo -i 然后 pip3 install <package-name>。有时,这会使 import <package-name> 在 Jupyter 中的 python3 笔记本上工作。但通常不是。然后,如果我改为执行 pip install ,则可以从服务器上的笔记本(python3 个,全部)访问该包。这是为什么?

这是我的:

~# which python 
/anaconda3/bin/python

~# which python3 
/anaconda3/bin/python3

~# which pip 
/anaconda3/bin/pip

~# which pip3 
/anaconda3/bin/pip3

~# which jupyter 
/anaconda3/bin/jupyter

我找到了问题的答案here:

pip3 always operates on the Python3 environment only, as pip2 does with Python2. pip operates on whichever environment is appropriate to the context. For example if you are in a Python3 venv, pip will operate on the Python3 environment.