哪个点与哪个python?

Which pip is with which python?

这让我发疯。我试图删除 mac os x el capitan 上安装的 python 的所有软件包并重新安装 brew install pythonpip。我这里有:

which pip
/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/bin/pip

which python
/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/bin/python

所以使用 pip list

pip list
cycler (0.10.0)
matplotlib (1.5.1)
numpy (1.11.0)
pip (8.1.2)
python-dateutil (2.5.3)
pytz (2016.4)
setuptools (19.4)
six (1.10.0)
wheel (0.26.0)

但是我运行python的时候没有调用numpy和matplotlib的模块:

python
Python 2.7.11 (default, Jan 22 2016, 08:29:18) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named numpy
>>> import matplotlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 122, in <module>
    from matplotlib.cbook import is_string_like, mplDeprecation, dedent, get_label
  File "/usr/local/lib/python2.7/site-packages/matplotlib/cbook.py", line 33, in <module>
    import numpy as np
ImportError: No module named numpy

这是我的 sys.path:

sys.path
['', '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/site-packages/gtk-2.0']

您可以 运行 pip 通过 运行 将特定版本的 Python 作为模块使用。命令行参数就像直接从命令行 运行ning 一样工作。例如,尝试:

python -m pip list

如果仍然列出 numpy,则可能意味着 numpy 安装有问题 — 即 .egg 文件存在,但模块文件夹不存在。要尝试解决此问题,您可以使用 --force-reinstallpip,例如

python -m pip install numpy --force-reinstall --upgrade

如果 仍然 不起作用,您可以求助于转到 sys.path 报告的文件夹并手动删除任何 numpy 相关内容。

由于您的 pip 设置似乎一团糟,您可能也想尝试重新安装 pip

最准确的方法是从特定的 python 可执行文件调用 pip。例如:

/usr/bin/python -m pip list -v
/usr/local/bin/python3 -m pip list -v