Search code examples
pythonpipsudoimporterroreasy-install

Python ImportError: no module named os


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.


Solution

  • 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.