7

This is driving me crazy. I have tried to remove all the packages of python installed on mac os x el capitan and re-installed brew install python and pip. Here I have :

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

and

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

so using 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)

However, when I run python, there is no module called numpy and 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

and this is my 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']
Amir
  • 1,348
  • 3
  • 21
  • 44
  • It is not saying there is no `matplotlib`, both error messages are saying there is no numpy. Did you try reinstalling numpy? – cdarke Jun 06 '16 at 16:31
  • what do you see when you execute `which pip` and `which python`? – Paul H Jun 06 '16 at 16:45
  • Are you sure numpy compiled correctly? It depends on a bunch of C libraries. You could also try just ```pip install numpy``` to check the exit status. And finally, you could pip update pip itself just like ```pip install pip --update``` if that really is the issue here (which I doubt). – Falk Schuetzenmeister Jun 06 '16 at 16:48

2 Answers2

9

You can run pip with a specific version of Python by running it as a module. Command line arguments work just as if running directly from the command line. For example, try:

python -m pip list

If that still lists numpy it probably means there is something wrong with the numpy installation — i.e. the .egg file is there, but the module folder is not. To try and fix this you can use --force-reinstall with pip, e.g.

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

If that still doesn't work, you can resort to going to the folder reported by sys.path and deleting anything numpy related manually.

Since your pip setup seems messed up you might want to try reinstalling pip too!

mfitzp
  • 15,275
  • 7
  • 50
  • 70
  • 2
    I'd recommend trying to [force reinstall numpy](http://stackoverflow.com/questions/19548957/can-i-force-pip-to-reinstall-the-current-version) before manually deleting files from the python installation folders. – Tadhg McDonald-Jensen Jun 06 '16 at 21:28
  • @TadhgMcDonald-Jensen thanks for the suggestion, much better first step. – mfitzp Jun 06 '16 at 21:31
2

The most accurate method is to call pip from the specific python executable. For example:

/usr/bin/python -m pip list -v
/usr/local/bin/python3 -m pip list -v
wisbucky
  • 33,218
  • 10
  • 150
  • 101