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

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

问题描述

我成功地在我的mac os x上为Python 2.7.3构建/安装了NumPy。
现在我想建立/安装scipy。我从git hub下载了它。
进入目录。冉python setup.py构建,它似乎工作,直到遇到此错误:

 自定义Gnu95FCompiler 
可能找不到可执行文件gfortran
无法找到可执行文件f95
自定义NAGFCompiler
自定义AbsoftFCompiler
无法找到可执行文件f90
无法找到可执行文件f77
自定义IBMFCompiler
无法找到可执行文件xlf90
无法找到可执行文件xlf
自定义IntelFCompiler
无法找到可执行文件ifort
无法找到可执行文件ifc
自定义GnuFCompiler
无法找到可执行文件g77
自定义G95FCompiler
无法找到可执行文件g95
自定义PGroupFCompiler
找不到可执行文件pgfortran
不知道如何编译Fortran代码平台'posix'
构建'dfftpack'库
错误:库dfftpack具有Fortran源代码但未找到Fortran编译器

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

解决方案

你的问题是你需要安装一个Fortran编译器来构建另外,如果您已经有一个使用Fortran支持构建的 numpy ,那么您可以使用

禁用,您可能需要更换它。一些预装的Python版本预装了 numpy 版本。






获取Fortran的最简单方法是使用自制软件。正如文档所述,您需要先安装Xcode及其命令行工具。 (安装命令行工具的方式几乎与Xcode的每个主要版本都有所不同,因此请参阅链接的文档以获取最新的解释。)然后安装Homebrew。安装网址已更改了几次,请参阅Homebrew主页或安装说明( http://brew.sh/),但它会是这样的:

  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安装gcc 。)






您真的想要使用 pip 安装 scipy ,所以如果你没有那个,就先拿它。苹果预装的Python,至少在10.7和10.8中包含 easy_install 但不是 pip ,所以最简单的方法这样做是:

pre $ sudo easy_install pip
$ c $ <$ pre>

但是,您可能需要考虑使用 virtualenv 而不是全局安装(在这种情况下,您还希望在以下命令中删除 sudo )。现在你已经有了 gfortran pip ,所有你必须这样做:

  sudo pip install --upgrade numpy 
sudo pip install scipy






警告:


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


  • 如果您已经有 pip ,但是担心它可能会过期, pip install --upgrade pip 。 (除了安全性和健壮性的好处之外,通过使您可以与一些科学堆栈或其他模块的二进制轮子兼容,这可以为您节省大量时间。)


  • 对于大多数非Apple的Python安装(甚至可能是苹果公司的10.9或10.10;我没有检查过),您应该 使用 easy_install 安装 pip 。遵循 pip 安装说明。但首先确保你还没有它。




    • 如果您使用 virtualenv / venv ,您的虚拟环境将包含 pip

    • Python 3.4或更高版本可能(并且如果来自python.org安装程序)包含 pip bootstrap 。如果你的3.4+还没有 pip ,你可能需要 python -m ensurepip 来安装它。 / li>
    • 一些第三方安装,如Homebrew或ActiveState,包含 pip


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


  • 如果您使用的是MacPorts,Fink,gentoo-alt等,您应该安装软件包附带的 scipy 包管理员,它会拖拽任何它需要的东西(甚至可能包括重建Python和GCC)。

  • 第二方安装像Enthought和ActiveState可能已经安装包括 scipy 和其他你需要的东西。如果没有,说明与上述基本相同,但是您必须猜测要跳过或关注哪些步骤,无论是 sudo 等。







如果您使用Python 2.7的非Apple版本,并且想要为避免PATH问题,您必须做两件事:首先,不要安装任何包含脚本或二进制文件的Python包(包括 pip 本身)。例如,如果为Apple 2.7和Homebrew 2.7安装 ipython ,则两者都会尝试创建名为 / usr / local / bin / ipython /usr/local/bin/ipython-2.7 。如果幸运的话,一次安装就会失败。否则,他们都会成功,最终会覆盖另一个,并且您将无法运行被覆盖的版本。

第二,确保路径替代Python的脚本和二进制文件在Apple的PATH之前。根据您安装的替代Python以及您遵循的指示,这可能是:



  • / 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变量。



如果您想要影响GUI应用程序(以及LaunchAgents等) ,显然不再有支持的方式来执行此操作,但已弃用的 QA1067 在Lion中似乎仍然有效。这也是Homebrew 常见问题 Python常见问题解答建议。



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



无论如何,您需要确保PATH中的 / usr / bin 之前存在适当的路径。因此,例如,您可以将以下内容添加到〜/ .profile

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

(如果您使用的是,那么您需要创建一个新的终端shell,或者在脚本生效前获取脚本。) 自制软件 brew doctor 会告诉你,如果你做得对。


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

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

解决方案

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

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.


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

Then:

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


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

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

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:

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

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

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

    • 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.
  • For Python 3.3 or later, you may want to use the built-in venv instead of virtualenv.

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

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


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:

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.

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
  • something else

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

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.

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.

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

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

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

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

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