繁体   English   中英

在Mac OS Lion上预装python 2.6.7的numpy和scipy

[英]numpy and scipy for preinstalled python 2.6.7 on mac OS Lion

无论如何,Mac OS Lion随附的python 2.6.7上是否要安装numpy和scipy? 我知道Lion也有Python 2.7。 但是我需要坚持使用Python 2.6,因为我使用的模块在Python 2.7上不起作用。

Lion为其每个Python实现都提供了easy_install/usr/bin/easy_install-2.7针对/usr/bin/python2.7 ,以及2.6和2.5。

但是,scipy需要一个Fortran编译器,而Lion并不附带其中之一。 看起来您必须先安装Fortran编译器才能安装numpy,否则以后将无法安装scipy。

首先,您需要Xcode命令行工具。 (Apple经常更改此软件包的名称-取决于您的Xcode版本,它可能是“ Unix开发工具”或“ CLI开发工具链”等。)

这些可以由Xcode本身安装。 如果您使用的是4.3.x,则从App Store安装Xcode后,启动它,转到“首选项”,“下载”,“组件”,然后单击“命令行工具”旁边的“安装”按钮。 对于不同的版本,或者如果要在不使用Xcode的情况下安装它们,则Homebrew页(请参见下文)说明了如何获取它们,或者可以在Apple的开发人员站点中浏览

如果您已经有了软件包管理器(Homebrew,MacPorts或Fink),请使用它。 如果不这样做,请安装Homebrew

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

然后像这样安装gfortran:

brew install gfortran

现在您已经准备安装numpy和scipy。 如果您喜欢pip而不是easy_install(如果您不知道,则可能更喜欢pip),则必须先安装:

sudo easy_install-2.6 pip

然后使用它来安装软件包:

sudo pip-2.6 install numpy

根据您的确切操作系统版本和其他详细信息,您可能已经为2.6内置了一个numpy,但是该numpy不支持Fortran。 您可以这样说是因为sudo pip-2.6 install numpy表示Requirement already satisfied (use --upgrade to upgrade): numpy in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python 解决方案是完全按照错误消息的说明进行操作:

sudo pip-2.6 install --upgrade numpy

最后:

sudo pip-2.6 install scipy

我在Mountain Lion上安装SciPy时遇到了类似的问题。

OSX山狮10.8

Python 2.7.3

点1.1

酿造0.9.2

GNU Fortran(GCC)4.2.1

我收到的一些错误包括:

这个:

pip install scipy

产生此错误:

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

这促使我寻找Fortran编译器:

该命令:

brew install gfortran

产生此错误:

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

这使我想到了一个博客文章: http : //www.joewandy.com/ 我遵循了此建议:

该命令:

brew edit gfortran

将使用xcode打开文件。 我在两个地方修改了该文件:

论文2行:

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

变成:

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"

换一种说法:

== 10.7更改为>= 10.7并将XCode 4.2 (build 5666)更改为XCode 4.2 (build 5666) or higher

然后我做了

brew install gfortran

再次。 消息成功:

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

然后我做了:

pip install scipy

但这给了我这个:

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

然后我找到了此博客文章:在Mountain Lion上编译SciPy http://www.thisisthegreenroom.com/2012/compiling-scipy-on-mountain-lion/

表示要使用此命令:

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

这大约需要5到6分钟才能完成

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

之后我可以做

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

成功!

已安装SciPy版本:

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

我认为您不需要安装Brew和XCode,也不需要自己编译gfortran:我从http://hpc.sourceforge.net安装了gfortran的编译版本,一切似乎都可以正常工作。 (我是10.7.5)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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