2

我正在尝试运行一个使用 Python 和 R 的 multipack Heroku 应用程序。我首先安装了 R 的 multi buildpack,但是尽管我对 $PATH 进行了修改,但 RPy 的安装无法找到 R。这里发生了什么?当 init.r 运行时,R 将 RHOME 视为“/app/vendor/R/lib64/R”。

-----> Fetching custom git buildpack... done
-----> Multipack app detected
=====> Downloading Buildpack: https://github.com/virtualstaticvoid/heroku-buildpack-r
=====> Detected Framework: R
   Vendoring R 2.15.1
   Downloading and unpacking R binaries
   Executing init.r script
[1] "/app/vendor/R/lib64/R" #This is me dumping out RHOME from init.r
   R 2.15.1 successfully installed
=====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-python
=====> Detected Framework: Python
-----> No runtime.txt provided; assuming python-2.7.4.
-----> Using Python runtime (python-2.7.4)
-----> Installing dependencies using Pip (1.3.1)
   Downloading/unpacking rpy2==2.3.5 (from -r requirements/base.txt (line 22))
     Running setup.py egg_info for package rpy2

       sh: R: not found
       Error: Tried to guess R's HOME but no R command in the PATH.
       Complete output from command python setup.py egg_info:
       running egg_info

   creating pip-egg-info/rpy2.egg-info

   writing pip-egg-info/rpy2.egg-info/PKG-INFO

   writing top-level names to pip-egg-info/rpy2.egg-info/top_level.txt

   writing dependency_links to pip-egg-info/rpy2.egg-info/dependency_links.txt

   writing manifest file 'pip-egg-info/rpy2.egg-info/SOURCES.txt'

   warning: manifest_maker: standard file '-c' not found



   sh: R: not found

   Error: Tried to guess R's HOME but no R command in the PATH.

   ----------------------------------------
   Command python setup.py egg_info failed with error code 1 in /tmp/pip-build-u32629/rpy2
   Storing complete log in /app/.pip/pip.log
 !     Heroku push rejected, failed to compile Multipack app

To git@heroku.com:D.git
 ! [remote rejected] master -> master (pre-receive hook declined)

(venvddd)ben@Watt:~/Projects/D/D$ heroku config:get PATH /home/ben/Projects/D/venvddd/bin:/usr/local/heroku/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/app/vendor/R/lib64/R:/app/vendor/R/lib64/R/bin
4

1 回答 1

1

在@bwarren2 提供了一些有用的建议后,我想我有了一种更简洁的方式来在 Heroku 上同时使用 R、python 和 rpy2。

在此示例中,我使用了 python buildpack heroku-buildpack-python-sklearn,其中包含来自二进制构建的 numpy、scipy 和 scikit-learn。Rpy2 库有很好的 numpy 集成,所以你可能想从这个开始。如果不是,那么同样的方法适用于普通的 python buildpack。

像这样制作一个 .buildpacks 文件:

https://github.com/virtualstaticvoid/heroku-buildpack-r.git
https://github.com/dbrgn/heroku-buildpack-python-sklearn/

安装 R 库的可选 init.r 文件,以及此 requirements.txt 文件:

numpy==1.7.0
scipy==0.11.0
scikit-learn==0.13.1
matplotlib==1.1.0
rpy2==2.3.8

因为我们正在获取这些的二进制版本(由于 BLAS 和其他依赖项),所以版本号必须完全匹配。

然后我们执行正常流程来使用多构建包。但是,python buildpack 需要知道 R 和一些库的安装位置。Heroku 上的 slug 构建系统不会将 R buildpack 中设置的所有环境变量传递给 python buildpack。

但是,我们可以使用 Heroku 实验室的新 user-env-compile 功能,并为 PATH 和 LD_LIBRARY_PATH 显式设置变量。这就是我所做的...

# make a test repo
git init 
# add our files
git add init.r
git add requirements.txt
git add .buildpacks
# commit the files
git ci -m"testing using user-env-compile"

# create a new app using the multi buildpack code
heroku create --buildpack https://github.com/ddollar/heroku-buildpack-multi.git

# turn on user-env-compile, that allows config vars when compiling slug
# see https://devcenter.heroku.com/articles/labs-user-env-compile
heroku labs:enable user-env-compile

# set the path variables explicitly, so python knows where R is located
heroku config:set PATH=/app/vendor/R/bin:/app/vendor/gcc-4.3/bin:/app/.heroku/python/bin:/usr/local/bin:/usr/bin:/bin
heroku config:set LD_LIBRARY_PATH=/usr/lib:/usr/local/lib:/app/vendor/R/lib64/R/modules:/app/vendor/R/lib64/R/lib:/app/vendor/gcc-4.3/lib64


# create the slug
git push heroku master

# we can now access R from python using rpy2
$ heroku run python
Running `python` attached to terminal... up, run.1144
Python 2.7.4 (default, Apr  6 2013, 22:14:13) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import rpy2.robjects as robjects
>>> pi = robjects.r['pi']
>>> pi[0] 
3.141592653589793

编辑:我更新了 LD_LIBRARY_PATH 以包含 /usr/lib 和 /usr/local/lib,以避免出现此处描述的问题

还将 matplotlib==1.1.0 添加到 requirements.txt,这是此处描述的旧版本。

于 2014-02-13T00:20:26.133 回答