问题
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.
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/28534506/python-importerror-no-module-named-os