简体   繁体   中英

numpy and scipy for preinstalled python 2.6.7 on mac OS Lion

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.

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

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:

pip install scipy

Yielded this error:

Could not locate executable pgfortran

don't know how to compile Fortran code on platform 'posix'

building 'dfftpack' library

error: library dfftpack has Fortran sources but no Fortran compiler found

Which led me to look for a Fortran compiler:

This command:

brew install gfortran

Which yielded this error:

Error: Currently the gfortran compiler provided by this brew is only supports the following versions of XCode:

    - XCode 3.1.4 on OS X 10.5.x
    - XCode 3.2.2/3.2.3 -- 4.0 on OS X 10.6.x
    - XCode 4.1 or newer on OS X 10.7.x

The AppStore and Software Update can help upgrade your copy of XCode.
The latest version of XCode is also available from:

http://developer.apple.com/technologies/xcode.html

Which led me to a blog post: http://www.joewandy.com/ . I followed this recommendation:

This command:

brew edit gfortran

will open a file using xcode. I modified this file in exactly two places:

Theses 2 lines:

if MacOS.xcode_version >= '4.2' and MACOS_VERSION == 10.7
    ohai "Installing gfortran 4.2.4 for XCode 4.2 (build 5666)"

Changed to:

if MacOS.xcode_version >= '4.2' and MACOS_VERSION >= 10.7
    ohai "Installing gfortran 4.2.4 for XCode 4.2 (build 5666) or higher"

in other words:

Changed == 10.7 to >= 10.7 and Changed XCode 4.2 (build 5666) to XCode 4.2 (build 5666) or higher

Then I did

brew install gfortran

again. which was successful with a message of:

Downloading http://r.research.att.com/tools/gcc-42-5666.3-darwin11.pkg

Already downloaded: /Library/Caches/Homebrew/gfortran-4.2.4-5666.3.pkg
==> Installing gfortran 4.2.4 for XCode 4.2 (build 5666) or higher
==> Caveats
Brews that require a Fortran compiler should not use:

depends_on 'gfortran'

The preferred method of declaring Fortran support is to use:

def install
    ...
    ENV.fortran
    ...
end

==> Summary

/usr/local/Cellar/gfortran/4.2.4-5666.3: 86 files, 72M, built in 2 seconds

Then I did:

pip install scipy

but that gave me this:

#error "<vecLib/vecLib.h> is deprecated.  Please #include <Accelerate/Accelerate.h> and link to Accelerate.framework."

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:

pip install -e git+https://github.com/scipy/scipy#egg=scipy-dev

This took about 5 to 6 minutes to complete

Installed /Users/hernamesbarbara/src/scipy
Successfully installed scipy
Cleaning up...

after which I could do

python


Python 2.7.3 (v2.7.3:70274d53c1dd, Apr  9 2012, 20:52:43) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy
>>> help(scipy)

    Help on package scipy:

NAME
    scipy

Success!

SciPy version installed:

full_version = '0.12.0.dev-14b1e07'
git_revision = '14b1e07602ff33a6e8250eb2bc7a6816677606a9'
release = False
short_version = '0.12.0'
version = '0.12.0.dev-14b1e07'

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)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM