Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
625 views
Welcome To Ask or Share your Answers For Others

1 Answer

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:

curl https://raw.github.com/gist/323731/25f99360c7de3f72027d8fd07cb369b1c8756ea6/install_homebrew.rb -o /tmp/install_homebrew.rb
ruby /tmp/install_homebrew.rb
rehash

Then install gfortran like this:

brew install gfortran

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:

sudo easy_install-2.6 pip

Then use it to install the packages:

sudo pip-2.6 install numpy

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 says Requirement 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:

sudo pip-2.6 install --upgrade numpy

And finally:

sudo pip-2.6 install scipy

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...