7

Matplotlib was working fine few months back. But now I keep getting the error:

ImportError: No module named matplotlib

I again installed matplotlib using pip. It didn't work. I used easyinstall. Still not working.

pip installation gives

Requirement already satisfied (use --upgrade to upgrade): matplotlib in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib-1.5.0-py2.7-macosx-10.6-intel.egg
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.6 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): python-dateutil in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/python_dateutil-2.4.2-py2.7.egg (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): pytz in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pytz-2015.7-py2.7.egg (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): cycler in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cycler-0.9.0-py2.7.egg (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): pyparsing!=2.0.0,!=2.0.4,>=1.5.6 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyparsing-2.0.6-py2.7.egg (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): six>=1.5 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/six-1.10.0-py2.7.egg (from python-dateutil->matplotlib)

Then I used

sudo -E pip install matplotlib --upgrade

after which i got

The directory '/Users/ruskin/Library/Logs/pip' or its parent directory is not owned by the current user and the debug log has been disabled.        Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/ruskin/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled.   Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
You are using pip version 6.1.1, however version 7.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
The directory '/Users/ruskin/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

It continued upgrading matplotlib but in the end i got

Requirement already up-to-date: python-dateutil in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/python_dateutil-2.4.2-py2.7.egg (from matplotlib)
Requirement already up-to-date: pytz in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pytz-2015.7-py2.7.egg (from matplotlib)
Requirement already up-to-date: cycler in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cycler-0.9.0-py2.7.egg (from matplotlib)
Requirement already up-to-date: pyparsing!=2.0.0,!=2.0.4,>=1.5.6 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyparsing-2.0.6-py2.7.egg (from matplotlib)
Requirement already up-to-date: six>=1.5 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/six-1.10.0-py2.7.egg (from python-dateutil->matplotlib)
Installing collected packages: numpy
  Found existing installation: numpy 1.9.1
 Uninstalling numpy-1.9.1:
  Exception:
  Traceback (most recent call last):
    File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 246, in main
      status = self.run(options, args)
    File "/Library/Python/2.7/site-packages/pip/commands/install.py", line 352, in run
      root=options.root_path,
    File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line 687, in install
      requirement.uninstall(auto_confirm=True)
    File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 730, in uninstall
      paths_to_remove.remove(auto_confirm)
    File "/Library/Python/2.7/site-packages/pip/req/req_uninstall.py", line 126, in remove
      renames(path, new_path)
    File "/Library/Python/2.7/site-packages/pip/utils/__init__.py", line 292, in renames
      shutil.move(old, new)
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 303, in move
      os.unlink(src)
  OSError: [Errno 13] Permission denied: '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy-1.9.1.dist-info/DESCRIPTION.rst'
ruskin23
  • 145
  • 1
  • 10
  • 2
    Check your `which python` path. – JRodDynamite Nov 24 '15 at 08:33
  • Please show output of `pip list` – Tomasz Jakub Rup Nov 24 '15 at 08:33
  • Read the answers to this question: [Pip Install not installing into correct directory?](http://stackoverflow.com/questions/25607837/pip-install-not-installing-into-correct-directory) – k4ppa Nov 24 '15 at 08:36
  • @TomaszJakubRup matplotlib (1.3.1) is available in pip list – ruskin23 Nov 24 '15 at 08:36
  • @JasonEstibeiro /Library/Frameworks/Python.framework/Versions/2.7/bin/python I think this is fine – ruskin23 Nov 24 '15 at 08:37
  • @k4ppa which python shows the directory is correct. – ruskin23 Nov 24 '15 at 08:40
  • `python -m pip install --upgrade matplotlib ` – Peter Wood Nov 24 '15 at 08:44
  • @PeterWood I used sudo -E pip install matplotlib --upgrade and this is what i got DEPRECATION: Uninstalling a distutils installed project (numpy) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project. And then Uninstalling numpy-1.8.0rc1: Exception: Traceback (most recent call last): File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 246, in main status = self.run(options, args) – ruskin23 Nov 24 '15 at 08:44
  • `brew install matplotlib` – Pavleg Nov 24 '15 at 08:44

1 Answers1

4

On OS X do not ever install python modules as root, is a quick recipe for never ending failures.

Use the --user parameter for pip in order to install modules for the current user only, like:

localhost:~ sorins$ which python
/usr/local/bin/python

python -m pip install --user --upgrade matplotlib

Also, be sure that you are using the correct python interpreters, as it happens often for pip to get confused and to install a module in a location than is not included in the python PATH (sys.path).

sorin
  • 161,544
  • 178
  • 535
  • 806