4

Trying to upgrade matplotlib as in this post, I ran

export PYTHONHOME=/usr/lib/python2.7/
sudo easy_install -U distribute
sudo pip install --upgrade matplotlib

Now whenever I try to run python I get ImportError: no module named os. What happened? Please help me. I'm on OS X 10.9.5.

Community
  • 1
  • 1
BoltzmannBrain
  • 5,082
  • 11
  • 46
  • 79
  • There are a couple of things to note here: a) `distribute` was discontinued in favor of `setuptools` b) `getpip.py` is the preferred way to bootstrap `setuptools` and `pip`. c) I would not recommend setting `PYTHONHOME`, but using ` -m pip install --upgrade matplotlib` d) installing directly into system's site-packages directory is usually avoided by using `virtualenv`'s. That said: Can you give us some hints which OS you are currently working on? – cel Feb 16 '15 at 06:49
  • What are you trying to do here? If you want to upgrade the 2.7 version of a library, just type `sudo pip2 install --upgrade matplotlib` - do not mess with environment variables. – Burhan Khalid Feb 16 '15 at 08:15
  • @cel thank you for the informative explanation. I'm on OS X 10.9.5. – BoltzmannBrain Feb 16 '15 at 13:29
  • @BurhanKhalid thank you, but how can I know fix this mess? – BoltzmannBrain Feb 16 '15 at 16:53

2 Answers2

4

The issue was changing PYTHONHOME, which could not find any modules because I have python running out of a user directory /Users/alavin89/Library/Python/2.7/lib/python/site-packages. Check the python path by running echo $PYTHONPATH. The fix:

unset PYTHONHOME
sudo pip uninstall matplotlib
pip uninstall matplotlib
pip install --user matplotlib

Note: running uninstall again w/o sudo is to double-check it worked properly.

BoltzmannBrain
  • 5,082
  • 11
  • 46
  • 79
  • Glad you could solve this issue. I would recommend looking into `virtualenv` or `anaconda` and get familiar with the concept of python environments. While these might seem to be a lot of overhead at first sight, you probably will love the concept very soon. – cel Feb 16 '15 at 17:27
-1

Use Anaconda.

https://store.continuum.io/cshop/anaconda/

It has every Python package you could possibly think of - including matplotlib - it updates them all at once as well.

Chef1075
  • 2,614
  • 9
  • 40
  • 57
  • 6
    This is not very good advice. While I use anaconda myself, it is misleading to say that they have `every` python package. Their focus is on scientific packages... – cel Feb 16 '15 at 15:27
  • It is how I solved my problems when my matplotlib was not working correctly. Looks like alavin89 gave a good answer, though. – Chef1075 Feb 16 '15 at 17:55