SciPy 构建/安装 Mac Osx [英] SciPy build/install Mac Osx

查看:26
本文介绍了SciPy 构建/安装 Mac Osx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我成功地在我的 mac os x 上为 python 2.7.3 构建/安装了 NumPy.现在我也想构建/安装 scipy.我是从 git hub 下载的.进入目录.运行 python setup.py build,它似乎一直在工作,直到遇到这个错误:

I successfully built/installed NumPy on my mac os x for python 2.7.3. Now I would like to build/install scipy as well. I downloaded it from git hub. Went into the directory. Ran python setup.py build and it seemed to be working until it came across this error:

customize Gnu95FCompiler
Could not locate executable gfortran
Could not locate executable f95
customize NAGFCompiler
customize AbsoftFCompiler
Could not locate executable f90
Could not locate executable f77
customize IBMFCompiler
Could not locate executable xlf90
Could not locate executable xlf
customize IntelFCompiler
Could not locate executable ifort
Could not locate executable ifc
customize GnuFCompiler
Could not locate executable g77
customize G95FCompiler
Could not locate executable g95
customize PGroupFCompiler
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

我以为我为 NumPy 安装了 Fortran...你猜不是?我将如何下载它?

I thought that I had Fortran installed for NumPy...guess not? How would I download it?

推荐答案

你的问题是你需要安装 Fortran 编译器来构建 scipy.

Your problem is that you need to install a Fortran compiler to build scipy.

此外,如果您已经有一个禁用 Fortran 支持的 numpy,您可能需要替换它.一些 Apple 预装的 Python 版本预装了这样的 numpy 构建.

Also, if you already have a numpy that's built with Fortran support disabled, you may have to replace it. Some of Apple's pre-installed Python versions have such a numpy build pre-installed.

获得 Fortran 的最简单方法是使用 Homebrew.正如文档所说,您需要首先安装 Xcode 及其命令行工具.(安装命令行工具的方式几乎随 Xcode 的每个主要版本而变化,因此请参阅链接的文档以获取最新说明.)然后安装 Homebrew.安装 URL 已更改几次,因此请参阅 Homebrew 主页或安装说明(http://brew.sh/),但它会是这样的:

The easiest way to get Fortran is with Homebrew. As the docs say, you need to install Xcode and its Command Line Tools first. (The way to install the Command Line Tools changes with almost each major version of Xcode, so see the linked docs for an up-to-date explanation.) Then install Homebrew. The installation URL has changed a few times, so see the Homebrew home page or installation instructions(http://brew.sh/), but it will be something like:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

那么:

brew install gcc

(请注意,直到 2014 年的某个时候,gfortran 是与 gcc 不同的配方,所以命令是 brew install gfortran.但是如果您现在尝试,您将收到一条错误消息,提示GNU Fortran 现在作为 GCC 的一部分提供,并且可以通过以下方式安装:brew install gcc".)

(Note that until some time in 2014, gfortran was a separate recipe from gcc, so the command was brew install gfortran. But if you try that now, you'll get an error saying "GNU Fortran is now provided as part of GCC, and can be installed with: brew install gcc".)

您确实想使用 pip 来安装 scipy,所以如果你没有那个,先得到它.Apple 预装的 Python,至少在 10.7 和 10.8 中,包括 easy_install 但不包括 pip,所以最简单的方法是:

You really want to use pip to install scipy, so if you don't have that, get it first. Apple's pre-installed Python, at least in 10.7 and 10.8, includes easy_install but not pip, so the easiest way to do that is:

sudo easy_install pip

但是,您可能需要考虑使用 virtualenv而不是全局安装(在这种情况下,您还想删除以下命令中的 sudo).

However, you may want to consider using a virtualenv instead of a global install (in which case you also want to remove the sudo on the following commands).

既然你已经有了 gfortranpip,你所要做的就是:

Now that you've got gfortran and pip, all you have to do is this:

sudo pip install --upgrade numpy
sudo pip install scipy

<小时>

注意事项:


Caveats:

  • 以上说明适用于 Apple 预装的 Python 版本.如果您使用的是不同版本的 Python,您真的应该考虑不这样做.保持路径、安装的软件包等同步是一场噩梦.例外情况是如果您想要 Python 3.x 版本,在这种情况下,从 python.org 或 Homebrew 安装它是完全合理的.不会有冲突,因为 pythonpip2.7 等将用于 Apple 的 Python;python3, pip3.3 等 3.x 版本.

  • The instructions above are for Apple's pre-installed version(s) of Python. If you're using a different version of Python, you really should consider not doing so. Keeping the paths, installed packages, etc. in sync is a nightmare. The exception to this is if you want a Python 3.x version, in which case installing it from python.org or Homebrew is perfectly reasonable. There will be no collisions, because python, pip2.7, etc. will be for Apple's Python; python3, pip3.3, etc. for the 3.x version.

如果您已经有 pip,但担心它可能已经过时,请pip install --upgrade pip.(除了安全性和稳健性优势之外,这可以让您与某些科学堆栈或其他模块的二进制轮兼容,从而为您节省大量时间.)

If you already have pip, but fear it may be out of date, pip install --upgrade pip. (Besides the security and robustness benefits, this may save you a whole lot of time by making you compatible with binary wheels for some of the scientific stack or other modules.)

对于大多数非 Apple Python 安装(甚至可能是 Apple 的 10.9 或 10.10;我还没有检查过),您应该不要使用 easy_install安装 pip.按照 pip 安装说明.但首先要确保你还没有它.

For most non-Apple Python installations (and maybe even Apple's in 10.9 or 10.10; I haven't checked), you should not use easy_install to install pip. Follow the pip install instructions. But first make sure you don't already have it.

  • 如果您使用 virtualenv/venv,您的虚拟环境将已经包含 pip.
  • Python 3.4 或更高版本可能(并且会,如果来自 python.org 安装程序)包含 pip 引导程序.如果您的 3.4+ 还没有 pip,您可能需要 python -m ensurepip 来安装它.
  • 某些第三方安装(例如 Homebrew 或 ActiveState)包括 pip.
  • If you're using virtualenv/venv, your virtual environments will already include pip.
  • Python 3.4 or later may (and will, if from a python.org installer) include a pip bootstrap. If your 3.4+ doesn't already have pip, you may want to python -m ensurepip to install it.
  • Some third-party installs, like Homebrew or ActiveState, include pip.

对于 Python 3.3 或更高版本,您可能需要使用内置的 venv 而不是 virtualenv.

For Python 3.3 or later, you may want to use the built-in venv instead of virtualenv.

如果你使用 MacPorts、Fink、gentoo-alt 等,你应该安装你的包管理器附带的 scipy 包,它会拖入任何其他东西需要(甚至可能包括重建 Python 和 GCC).

If you're using MacPorts, Fink, gentoo-alt, etc., you should install the scipy package that comes with your package manager, and it will drag in whatever else it needs (maybe even including rebuilding Python and GCC).

第三方二进制安装(如 Enthought 和 ActiveState)可能已经包含 scipy 和您需要的所有其他内容.如果没有,说明和上面基本一样,但是你必须猜测跳过或遵循哪些步骤,是否sudo

Third-party binary installs like Enthought and ActiveState may already include scipy and everything else you need. If not, the instructions are basically the same as above, but you'll have to guess which steps to skip or follow, whether to sudo, etc.

如果您使用的是非 Apple 版本的 Python 2.7,并且您想避免 PATH 问题,您必须做两件事:

If you're using a non-Apple build of Python 2.7, and you want to avoid the PATH problems, you have to do two things:

首先,永远不要在多个 Python 中安装任何包含脚本或二进制文件(包括 pip 本身)的 Python 包.例如,如果您为 Apple 2.7 和 Homebrew 2.7 安装 ipython,两者都将尝试创建名为 /usr/local/bin/ipython/usr 的脚本/local/bin/ipython-2.7.如果幸运的话,一次安装会失败.否则,它们都会成功,一个最终会覆盖另一个,而您将无法运行被覆盖的版本.

First, do not, ever, install any Python packages that include scripts or binaries (including pip itself) in more than one Python. For example, if you install ipython for both Apple 2.7 and Homebrew 2.7, both will attempt to create scripts named /usr/local/bin/ipython and /usr/local/bin/ipython-2.7. If you're lucky, one install will fail. Otherwise, they'll both succeed, one will end up overwriting the other, and you will have no way of running the overwritten version.

其次,确保替代 Python 脚本和二进制文件的路径在 PATH 中位于 Apple 之前.根据您安装的替代 Python 以及您遵循的说明,这可能是:

Second, make sure the path to the alternate Python's scripts and binaries comes before Apple's in the PATH. Depending on which alternate Python you've installed and which instructions you followed, this could be:

  • /usr/local/bin
  • /Library/Frameworks/Python.framework/Versions/2.7/bin
  • /usr/local/share/python2.7/bin
  • /usr/local/Cellar/python/2.7.3/bin
  • 别的东西

无论路径是什么,您都需要编辑 PATH 变量.

Whatever the path is, you need to edit your PATH variable.

如果您想影响 GUI 应用程序(和 LaunchAgents 等),显然不再支持执行此操作的方法,但不推荐使用 QA1067 似乎在 Lion 中仍然有效.这也是 Homebrew FAQPython 常见问题解答 建议.

If you want to affect GUI apps (and LaunchAgents, etc.), there is apparently no longer a supported way to do this, but the deprecated QA1067 does seem to still work in Lion. It's also what the Homebrew FAQ and Python FAQ suggest.

如果您只关心命令行会话(Terminal.app 和远程 ssh),您可以改为执行标准的 Unix 操作,即编辑适当的配置文件.哪个配置文件合适取决于您想要影响的内容.(所有用户还是只有一个用户?bash 还是任何 shell?等等.)如果你不知道你想要哪一个,你真的应该做一些研究.如果你不想费心学习,就做 ~/.profile 然后如果它不是你想要的就不要抱怨.

If you only care about command-line sessions (both Terminal.app and remote ssh), you can instead just do the standard Unix thing of editing the appropriate profile file. Which profile file is appropriate depends on what you want to affect. (All users or just one user? bash or any shell? And so on.) If you don't know which one you want, you really should do some research. If you don't want to bother learning, just do ~/.profile and then don't complain if it wasn't what you wanted.

无论哪种方式,您都需要确保适当的路径出现在 PATH 中 /usr/bin 之前.因此,例如,您可以将以下内容添加到 ~/.profile:

Either way, you need to make sure that the appropriate path comes before /usr/bin in the PATH. So, for example, you could add the following to ~/.profile:

PATH=/usr/local/bin:$PATH
export PATH

(您当然需要创建一个新的终端 shell,或者在它生效之前获取脚本的源.)

(You will of course need to either create a new Terminal shell, or source the script, before it takes effect.)

如果您使用的是 homebrewbrew doctor 会告诉您是否正确.

If you're using homebrew, brew doctor will tell you if you got it right.

这篇关于SciPy 构建/安装 Mac Osx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆