Python SciPy 构建/安装 Mac Osx
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14821297/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SciPy build/install Mac Osx
提问by Megan
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:
我成功地在我的 mac os x 上为 python 2.7.3 构建/安装了 NumPy。现在我也想构建/安装 scipy。我是从 git hub 下载的。进入目录。运行 python setup.py build ,它似乎一直在工作,直到遇到此错误:
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?
我以为我为 NumPy 安装了 Fortran ......你猜不是?我将如何下载它?
采纳答案by abarnert
Your problem is that you need to install a Fortran compiler to build scipy.
您的问题是您需要安装 Fortran 编译器来构建scipy.
Also, if you already have a numpythat's built with Fortran support disabled, you may have to replace it. Some of Apple's pre-installed Python versions have such a numpybuild pre-installed.
此外,如果您已经有一个numpy禁用 Fortran 支持的构建,则可能需要替换它。一些 Apple 预装的 Python 版本numpy预装了这样的构建。
The easiest way to get Fortran is with Homebrew. As the docssay, 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:
获得 Fortran 的最简单方法是使用Homebrew。正如文档所说,您需要先安装 Xcode 及其命令行工具。(安装命令行工具的方式几乎随 Xcode 的每个主要版本而变化,因此请参阅链接的文档以获取最新说明。)然后安装 Homebrew。安装 URL 已经更改了几次,因此请参阅 Homebrew 主页或安装说明(http://brew.sh/),但它会是这样的:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Then:
然后:
brew install gcc
(Note that until some time in 2014, gfortranwas 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".)
(请注意,直到 2014 年的某个时候,它gfortran是一个单独的配方gcc,所以命令是brew install gfortran。但是如果你现在尝试,你会得到一个错误说“GNU Fortran 现在作为 GCC 的一部分提供,并且可以安装:brew install gcc“。)
You really want to use pipto 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_installbut not pip, so the easiest way to do that is:
您确实想使用pipto install scipy,所以如果您没有,请先获取。Apple 预装的 Python,至少在 10.7 和 10.8 中,包括easy_install但不包括pip,因此最简单的方法是:
sudo easy_install pip
However, you may want to consider using a virtualenvinstead of a global install (in which case you also want to remove the sudoon the following commands).
但是,您可能需要考虑使用 avirtualenv而不是全局安装(在这种情况下,您还想删除sudo以下命令中的 )。
Now that you've got gfortranand pip, all you have to do is this:
现在你已经有了gfortranand pip,你所要做的就是:
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 notuse
easy_installto installpip. Follow thepipinstall instructions. But first make sure you don't already have it.- If you're using
virtualenv/venv, your virtual environments will already includepip. - Python 3.4 or later may (and will, if from a python.org installer) include a
pipbootstrap. If your 3.4+ doesn't already havepip, you may want topython -m ensurepipto install it. - Some third-party installs, like Homebrew or ActiveState, include
pip.
- If you're using
For Python 3.3 or later, you may want to use the built-in
venvinstead ofvirtualenv.If you're using MacPorts, Fink, gentoo-alt, etc., you should install the
scipypackage 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
scipyand 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 tosudo, etc.
以上说明适用于 Apple 预装的 Python 版本。如果您使用的是不同版本的 Python,您真的应该考虑不这样做。保持路径、安装的软件包等同步是一场噩梦。例外情况是,如果您想要 Python 3.x 版本,在这种情况下,从 python.org 或 Homebrew 安装它是完全合理的。不会有任何冲突,因为
python,pip2.7等将成为苹果的Python的;python3,pip3.3, 等适用于 3.x 版本。如果您已经拥有
pip,但担心它可能已过时,pip install --upgrade pip. (除了安全性和健壮性优势之外,通过使您与某些科学堆栈或其他模块的二进制轮兼容,这可以为您节省大量时间。)对于大多数非苹果的Python安装(甚至是苹果在10.9或10.10;我没有检查),你应该不使用
easy_install安装pip。按照pip安装说明进行操作。但首先要确保你还没有它。- 如果您使用
virtualenv/venv,您的虚拟环境将已经包含pip. - Python 3.4 或更高版本可能(并且将,如果来自 python.org 安装程序)包含
pipbootstrap。如果您的 3.4+ 还没有pip,您可能需要python -m ensurepip安装它。 - 一些第三方安装,如 Homebrew 或 ActiveState,包括
pip.
- 如果您使用
对于 Python 3.3 或更高版本,您可能希望使用内置
venv而不是virtualenv.如果你使用 MacPorts、Fink、gentoo-alt 等,你应该安装
scipy你的包管理器附带的包,它会拖入它需要的任何其他东西(甚至可能包括重建 Python 和 GCC)。第三方二进制安装(如 Enthought 和 ActiveState)可能已经包含
scipy您需要的所有其他内容。如果没有,说明与上面基本相同,但您必须猜测要跳过或遵循哪些步骤,是否要sudo,等等。
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:
如果您使用的是非 Apple 版本的 Python 2.7,并且想要避免 PATH 问题,则必须做两件事:
First, do not, ever, install any Python packages that include scripts or binaries (including pipitself) in more than one Python. For example, if you install ipythonfor both Apple 2.7 and Homebrew 2.7, both will attempt to create scripts named /usr/local/bin/ipythonand /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.
首先,永远不要pip在多个Python 中安装任何包含脚本或二进制文件(包括其自身)的 Python 包。例如,如果您同时安装ipythonApple 2.7 和 Homebrew 2.7,两者都会尝试创建名为/usr/local/bin/ipython和 的脚本/usr/local/bin/ipython-2.7。如果幸运的话,一次安装会失败。否则,它们都会成功,一个最终会覆盖另一个,并且您将无法运行被覆盖的版本。
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:
其次,确保替代 Python 脚本和二进制文件的路径在 PATH 中位于 Apple 之前。根据您安装的替代 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- something else
/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- 别的东西
Whatever the path is, you need to edit your PATH variable.
无论路径是什么,您都需要编辑 PATH 变量。
If you want to affect GUI apps (and LaunchAgents, etc.), there is apparently no longer a supported way to do this, but the deprecated QA1067does seem to still work in Lion. It's also what the Homebrew FAQand Python FAQsuggest.
如果您想影响 GUI 应用程序(和 LaunchAgents 等),显然不再支持执行此操作的方法,但已弃用的QA1067似乎在 Lion 中仍然有效。这也是 Homebrew FAQ和Python FAQ 所建议的。
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 ~/.profileand then don't complain if it wasn't what you wanted.
如果您只关心命令行会话(Terminal.app 和远程 ssh),您可以改为执行标准的 Unix 操作,即编辑适当的配置文件。哪个配置文件合适取决于您想要影响的内容。(所有用户还是只有一个用户?bash 还是任何 shell?等等。)如果你不知道你想要哪一个,你真的应该做一些研究。如果你不想打扰学习,~/.profile那就去做,如果这不是你想要的,不要抱怨。
Either way, you need to make sure that the appropriate path comes before /usr/binin the PATH. So, for example, you could add the following to ~/.profile:
无论哪种方式,您都需要确保适当的路径出现/usr/bin在 PATH之前。因此,例如,您可以将以下内容添加到~/.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.)
(您当然需要在它生效之前创建一个新的终端 shell,或获取脚本。)
If you're using homebrew, brew doctorwill tell you if you got it right.
如果您正在使用homebrew,brew doctor会告诉您是否做对了。
回答by Megan
i have homebree installed so I'm going to try: $brew install gfortran hopefully this works
我安装了 homebree 所以我要尝试: $brew install gfortran 希望这有效
回答by BenDundee
Here are detailed instructions for a clean install on OSX 10.7. If I were you, I'd go this route instead of trying to download and build the sources yourself.
以下是在 OSX 10.7 上进行全新安装的详细说明。如果我是你,我会走这条路,而不是尝试自己下载和构建源代码。
http://www.thisisthegreenroom.com/2011/installing-python-numpy-scipy-matplotlib-and-ipython-on-lion/
http://www.thisisthegreenroom.com/2011/installing-python-numpy-scipy-matplotlib-and-ipython-on-lion/
回答by abarnert
It looks like your actual problem was just an intermittent download failure from Sourceforge:
看起来您的实际问题只是来自 Sourceforge 的间歇性下载失败:
curl: (33) HTTP server doesn't seem to support byte ranges. Cannot resume. Error: Download failed: downloads.sf.net/project/machomebrew/Bottles/…
Homebrew should just recover automatically from this error if you try brew install gfortranagain. So, that's the first thing to try.
如果您再试brew install gfortran一次,Homebrew 应该会自动从此错误中恢复。所以,这是要尝试的第一件事。
If that doesn't work, see if brew doctorfinds any problems, then brew install -d gfortranto see where it's storing the partially-downloaded file so you can delete it manually and try again.
如果这不起作用,请查看是否brew doctor发现任何问题,然后brew install -d gfortran查看它存储部分下载的文件的位置,以便您可以手动删除它并重试。
If all else fails, you can force it to not use the bottle by using --build-from-source. Of course building from source takes a lot longer than installing a binary bottle, but it should give the same result.
如果所有其他方法都失败了,您可以使用 强制它不使用瓶子--build-from-source。当然,从源代码构建比安装二进制瓶需要更长的时间,但它应该给出相同的结果。
回答by BITTNT
I don't think this problem is too complicated at all.
我不认为这个问题太复杂。
1) Install pip
1)安装pip
cd /Library/Frameworks/Python.framework/Versions/ ln -s 2.7 Current
cd /Library/Frameworks/Python.framework/Versions/ ln -s 2.7 当前
cd /usr/bin rm -f python ln -s /Library/Frameworks/Python.framework/Versions/Current/bin/python python
cd /usr/bin rm -f python ln -s /Library/Frameworks/Python.framework/Versions/Current/bin/python python
2) download egg from https://pypi.python.org/pypi/setuptools#filessudo sh setuptools-0.6c11-py2.7.egg
2) 从https://pypi.python.org/pypi/setuptools#files下载 egg sudo sh setuptools-0.6c11-py2.7.egg
3) Simply download and install the gfotran from this link: http://r.research.att.com/tools/
3) 只需从此链接下载并安装 gfotran:http://r.research.att.com/tools/
4) After that, you need to type: sudo pip install -U scipy sudo pip install -U numpy sudo pip install -U matplotlib
4)之后,您需要键入:sudo pip install -U scipy sudo pip install -U numpy sudo pip install -U matplotlib
Hopefully, you should have everything you want to have.
希望你应该拥有你想要的一切。
回答by rchardzhu
I met the same problem, using following steps:
1. brew install gfortran
2. pip install scipy
我遇到了同样的问题,使用以下步骤:
1. brew install gfortran
2. pip install scipy
then it's ok.
那么就可以了。
回答by Mark Chackerian
As of 5/20/2014, if you're using brew, Fortran is installed as part of gcc. There is no separate Fortran package required. Here's what worked for me to install numpy:
截至 2014 年 5 月 20 日,如果您使用 brew,Fortran 将作为 gcc 的一部分安装。不需要单独的 Fortran 包。以下是我安装 numpy 的方法:
- install brew, as per abamert's answer (or see http://brew.sh/)
- install gcc (
brew install gcc) - confirm that brew's gcc is the correct one (
which gccshould point to /usr/local/bin/gcc ) export ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future(see Problems with pip install numpy - RuntimeError: Broken toolchain: cannot link a simple C program)pip install numpy
- 安装 brew,按照 abamert 的回答(或参见http://brew.sh/)
- 安装 gcc (
brew install gcc) - 确认 brew 的 gcc 是正确的(
which gcc应该指向 /usr/local/bin/gcc ) export ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future(请参阅pip install numpy 的问题 - RuntimeError: Broken toolchain: cannot link a simple C program)pip install numpy
回答by André Augusto
I had gfortraninstalled and the binary was gfortran-4.2. So, everytime I was trying to install SciPy the compiler couldn't be found because it was trying to use gfortran.
我安装了gfortran并且二进制文件是gfortran-4.2。所以,每次我尝试安装 SciPy 时都找不到编译器,因为它试图使用gfortran。
What I did was create a symlink of gfortran-4.2to gfortran.
我所做的是创建gfortran-4.2到gfortran的符号链接。
To find where you should create the symlink run:
要找到应该在哪里创建符号链接,请运行:
$ which gfortran-4.2
/usr/local/bin/gfortran-4.2
Then symlink it:
然后符号链接它:
ln -s /usr/local/bin/gfortran-4.2 /usr/local/bin/gfortran
回答by Masum
For OSX yosemite and possibly older osx releases too, you may want to download and install the fortran compiler before running pip install scipy. To download the latest fortran compiler, just go to the following link:
对于 OSX yosemite 和可能的较旧 osx 版本,您可能需要在运行pip install scipy. 要下载最新的 fortran 编译器,只需转到以下链接:
回答by dhltp
I think your version of Xcode and OSX matter. I had Xcode: 6.4 and Os X 10.11.1 and was still getting the same error messages (could not locate gfortran, etc). I tried many things, including the thorough response by @abarnert, but the solution for me was upgraded Xcode (to 7.1.1).
我认为您的 Xcode 和 OSX 版本很重要。我有 Xcode: 6.4 和 Os X 10.11.1 并且仍然收到相同的错误消息(无法找到 gfortran 等)。我尝试了很多事情,包括@abernert 的彻底回应,但我的解决方案是升级 Xcode(到 7.1.1)。

