Python ImportError: no module named os

那年仲夏 提交于 2020-01-11 09:39:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!