本文介绍了在Mac OS Lion上预装python 2.6.7的numpy和scipy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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带有 easy_install 表示其每个Python实现:/usr/bin/easy_install-2.7表示/usr/bin/python2.7,同样适用于2.6和2.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.

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

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.

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

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.)

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

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.

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

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

然后像这样安装gfortran:

Then install gfortran like this:

brew install gfortran

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

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

根据确切的操作系统版本和其他详细信息,您可能已经为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.解决方案是完全按照错误消息中的说明进行操作:

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

最后:

sudo pip-2.6 install scipy

这篇关于在Mac OS Lion上预装python 2.6.7的numpy和scipy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 14:22