问题
I installed matplotlib from macports, and version of python is 2.7.1.
$ sudo port install py27-matplotlib py27-matplotlib-basemap
I wrote a sample program below.
#!/usr/bin/python
# -*- coding: utf-8 -*-
from pylab import *
plot([1,2,3])
show()
But this didn't work correctly with error log "no module named pylab".
And I tried easy_install.
$ sudo easy_install matplotlib
In this case, my program worked correctly with no errors.
What is the difference between these two cases(macports and easy_install)?
I think the version of matplotlib is same in two cases.
In case of macports, do I have to redefine include path?
Would you help me??
回答1:
To ensure a compatible environment, MacPorts Python packages automatically install a MacPorts Python. By default, you can invoke it via /opt/local/bin/python2.7
. And that's where you will find the MacPorts installed matplotlib
et al. /usr/bin/python
will invoke the Apple-supplied system Python 2.7.1 and, when you ran sudo easy_install
you were using the Apple-supplied easy_install
command associated with the system Python. That means you now have two Python 2.7 instances installed, each with a separate version of matplotlib
. There's nothing wrong with that but you probably want to stick with one or the other. You can make the MacPorts Python 2.7 be your default by ensuring your SHELL path has /opt/local/bin
before /usr/bin
and by using the MacPorts port select python python27
command.
回答2:
As mentioned by Ned Deily, the problem is caused because MacPorts installs a separate Python even though OS X ships its own version.
I would suggest you use Homebrew instead of MacPorts to avoid problems like this. Homebrew will use the available package on OS X when possible.
Another suggestion is that it's better to use pip to manage Python package, which is a replacement for easy_install
and supports uninstalling packages. The benefit of using packaging system (like MacPorts, Debian's apt
) to manage python package is that they can solve the dependency if the Python package relies on other C libraries. But in case the some Python packages are not included in MacPorts or apt
, you will need to resolve to easy_install
or pip
. And it's usually not a good idea to use two packaging system to manage your python package at the same time.
来源:https://stackoverflow.com/questions/8543148/i-want-to-use-matplotlib-in-osx-lion