I have tried easy_install matplotlib and have the following:
matplotlib-1.2.0-py2.7-macosx-10.7-intel.egg
installed in my Library/Python/2.7/site-packages.
When I move to a different folder to make use of contents in that folder and try to
"import matplotlib.pyplot" it says : ImportError: No module named matplotlib.pyplot
This makes me think that the easy_install has been done incorrectly. This question is quite basic but I am working with mac osx and other than learn that it is incredibly hard to install this module on osx I have learnt little else from most sources so I would like to know if anyone on SO can help me with my problem. I am a python novice and would really appreciate the help.
As a general rule, you should always use pip
instead of easy_install
, except for a handful of libraries (all of which document that fact, and the only ones you're likely to care about are readline
, and of course pip
itself).
If you're on OS X 10.7 or 10.8, using the Apple-installed Python, you have easy_install
built-in, but not pip
. To fix that:
sudo easy_install pip
And now, you can do this:
sudo pip install matplotlib
Normally, this won't actually solve the kind of problem you're having. The reason to use pip
is that easy_install
has no uninstall functionality, it handles upgrades badly, it can end up leaving stuff part-way installed when it fails, it doesn't work right with virtualenv, etc.
But it sounds like you got lucky, and this change magically fixed your problem. We could try to diagnose the original problem. (Why were you using -m
with easy_install
? Does pip install --egg
work? And so on.) But I'm guessing you're happy with the result and just want to leave well-enough alone.
For future readers who come along, it seems like sudo easy_install -m matplotlib
on the stock Apple 10.7 Python 2.7 does not work, but sudo pip install matplotlib
does, and that may be good enough for them as well.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.