哪个pip与哪个python?

时间:2016-06-06 16:04:02

标签: python numpy matplotlib homebrew

这让我发疯了。我试图删除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']

1 个答案:

答案 0 :(得分:3)

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

python -m pip list

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

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

如果无法正常工作,您可以转到sys.path报告的文件夹,并手动删除任何与numpy相关的文件。

由于您的pip设置似乎搞砸了,您可能还想尝试重新安装pip