簡體   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