Is there anyway to install numpy and scipy on python 2.6.7 that comes with Mac OS Lion? I am aware that Lion has Python 2.7 as well. But I need to stick with Python 2.6 cause I am using a module that does not work on Python 2.7.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
I think you don't need to install Brew and XCode, nor compile gfortran yourself: I installed a compiled version of gfortran from http://hpc.sourceforge.net and everything seems to be working. (I am on 10.7.5)
Lion comes with an easy_install for each of its Python implementations:
/usr/bin/easy_install-2.7
for/usr/bin/python2.7
, and likewise for 2.6 and 2.5.However, scipy requires a Fortran compiler, and Lion doesn't come with one of those. It also looks like you have to have the Fortran compiler in place before installing numpy, or scipy can't be installed later.
First, you need the Xcode Command Line Tools. (Apple frequently changes the name of this package—it may be "Unix Development Tools", or "CLI Development Toolchain", etc., depending on your Xcode version.)
These can be installed by Xcode itself. If you're using 4.3.x, after installing Xcode from the App Store, launch it, go to Preferences, Downloads, Components, and click the Install button next to "Command Line Tools". For different versions, or if you want to install them without Xcode, the Homebrew page (see below) explains how to get them, or you can look around Apple's developer site.
If you've already got a package manager (Homebrew, MacPorts, or Fink), use that. If you don't, install Homebrew:
Then install gfortran like this:
Now you're ready to install numpy and scipy. If you prefer pip to easy_install (if you don't know, you probably prefer pip), you have to install that first:
Then use it to install the packages:
Depending on your exact OS version and other details, you may already have a built-in numpy for 2.6, but that numpy doesn't have Fortran support. You can tell this because
sudo pip-2.6 install numpy
saysRequirement already satisfied (use --upgrade to upgrade): numpy in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
. The solution is to do exactly what the error message says:And finally:
I was running into similar issues installing SciPy on Mountain Lion.
OSX Mountain Lion 10.8
Python 2.7.3
pip 1.1
brew 0.9.2
GNU Fortran (GCC) 4.2.1
Some of the errors I was receiving include:
This:
Yielded this error:
Which led me to look for a Fortran compiler:
This command:
Which yielded this error:
Which led me to a blog post: http://www.joewandy.com/. I followed this recommendation:
This command:
will open a file using xcode. I modified this file in exactly two places:
Theses 2 lines:
Changed to:
in other words:
Changed
== 10.7
to>= 10.7
and ChangedXCode 4.2 (build 5666)
toXCode 4.2 (build 5666) or higher
Then I did
again. which was successful with a message of:
Then I did:
but that gave me this:
Then I found this blog post: Compiling SciPy on Mountain Lion http://www.thisisthegreenroom.com/2012/compiling-scipy-on-mountain-lion/
which said to use this command:
This took about 5 to 6 minutes to complete
after which I could do
Success!
SciPy version installed: