在 Heroku 上运行 Scipy [英] Running Scipy on Heroku

查看:25
本文介绍了在 Heroku 上运行 Scipy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Heroku 上运行了 Numpy 和 Matplotlib,我也在尝试安装 Scipy.但是,Scipy 需要安装 BLAS[1],这在 Heroku 平台上没有提供.联系 Heroku 支持后,他们建议我将 BLAS 构建为静态库以进行部署,并设置必要的环境变量.

I got Numpy and Matplotlib running on Heroku, and I'm trying to install Scipy as well. However, Scipy requires BLAS[1] to install, which is not presented on the Heroku platform. After contacting Heroku support, they suggested me to build BLAS as a static library to deploy, and setup the necessary environment variables.

因此,我在 64 位 Linux 机器上编译了 libblas.a,并按照 [2] 中的描述设置了以下变量:

So, I compiled libblas.a on a 64bit Linux box, and set the following variables as described in [2] :

$ heroku config
BLAS             => .heroku/vendor/lib/libfblas.a
LD_LIBRARY_PATH  => .heroku/vendor/lib
LIBRARY_PATH     => .heroku/vendor/lib
PATH             => bin:/usr/local/bin:/usr/bin:/bin
PYTHONUNBUFFERED => true

在我的requirements.txt中加入scipy==0.10.1后,仍然推送失败.

After adding scipy==0.10.1 in my requirements.txt, the push still fails.

     File "scipy/integrate/setup.py", line 10, in configuration

       blas_opt = get_info('blas_opt',notfound_action=2)

     File "/tmp/build_h5l5y31i49e8/lib/python2.7/site-packages/numpy/distutils/system_info.py", line 311, in get_info

       return cl().get_info(notfound_action)

     File "/tmp/build_h5l5y31i49e8/lib/python2.7/site-packages/numpy/distutils/system_info.py", line 462, in get_info

       raise self.notfounderror(self.notfounderror.__doc__)

   numpy.distutils.system_info.BlasNotFoundError:

       Blas (http://www.netlib.org/blas/) libraries not found.

       Directories to search for the libraries can be specified in the

       numpy/distutils/site.cfg file (section [blas]) or by setting

       the BLAS environment variable.

似乎pip不知道BLAS环境变量,所以我使用heroku run python检查环境:

It seem that pip is not aware of the BLAS environment variable, so I check the environment using heroku run python:

(venv)bash-3.2$ heroku run python
Running python attached to terminal... import up, run.1
Python 2.7.2 (default, Oct 31 2011, 16:22:04) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.system('bash')
~ $ echo $BLAS
.heroku/vendor/lib/libfblas.a
~ $ ls .heroku/vendor/lib/libfblas.a
.heroku/vendor/lib/libfblas.a
~ $ 

而且看起来还不错.现在我不知道如何解决这个问题.

And it seems fine. Now I have no idea how to solve this.

[1] http://www.netlib.org/blas/[2] http://www.scipy.org/Installing_SciPy/Linux

推荐答案

通过将 numpy 和 scipy 离线构建为 bdists,然后修改 heroku python buildpack 以将它们解压缩到 dyno 的供应商/venv 区域直接.您还可以使用 buildpack 设置持续存在的环境变量.

I managed to get this working on the cedar stack by building numpy and scipy offline as bdists and then modifying the heroku python buildpack to unzip these onto the dyno's vendor/venv areas directly. You can also use the buildpack to set environment variables that persist.

Heroku 尚未正式发布构建包 - 搜索heroku buildpacks"以获取更多第三方/heroku 构建包和信息.

Heroku haven't officially published buildpacks yet - search for 'heroku buildpacks' for more thirdparty/heroku ones and information.

我的 python 构建包的分支在这里:https://wyn@github.com/wyn/heroku-buildpack-python.git

My fork of the python build pack is here: https://wyn@github.com/wyn/heroku-buildpack-python.git

更改位于 bin/compile 中,我从中获取了两个新步骤,一个 scipy/numpy 步骤和一个 openopt 步骤.这两个步骤的脚本在 bin/steps/npscipy 和 bin/steps/openopt 中.我还在 bin/release 中添加了一些变量.请注意,我假设通过 setup.py 文件而不是 requirements.txt 方法进行安装(参见 https://devcenter.heroku.com/articles/python-pip#traditional_distributions).

The changes are in the bin/compile where I source two new steps, a scipy/numpy step and an openopt step. The scripts for the two steps are in bin/steps/npscipy and bin/steps/openopt. I also added some variables to bin/release. Note that I am assuming installation through a setup.py file rather than the requirements.txt approach (c.f. https://devcenter.heroku.com/articles/python-pip#traditional_distributions).

我还下载了用于在 dyno 上构建 numpy/scipy 的 blas/lapack/atlas/gfortran 二进制文件,因为有 c 扩展需要链接到它们.离线构建和下载所有东西的原因是 pip 安装 numpy/scipy 需要你有一个 fortran 编译器 + 相关的开发环境,这使得我的 slug 太大了.

I also download the blas/lapack/atlas/gfortran binaries that were used to build numpy/scipy onto the dyno as there are c extensions that need to link through to them. The reason for building everything offline and downloading is that pip-installing numpy/scipy requires you to have a fortran compiler + associated dev environment and this made my slugs too big.

它似乎有效,slug 大小现在是 35mb,而且扩展似乎也很快.除了 numpy 测试之一通过之外,所有 scipy 测试都通过了.

It seems to work, the slug size is now 35mb and scaling seems fast too. All but one of the numpy tests pass and all of the scipy tests pass.

这对我来说仍在进行中,但我想我会分享.

This is still work in progress for me but I thought I'd share.

这篇关于在 Heroku 上运行 Scipy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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