Heroku RPy RHOME发现

时间:2013-05-08 08:07:10

标签: heroku

我正在尝试运行使用Python和R的multipack Heroku应用程序。我首先安装了R的multi buildpack,但是尽管我修改了$ PATH,RPy的安装仍然无法找到R.这里发生了什么? R认为RHOME为" / app / vendor / R / lib64 / R"当init.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

1 个答案:

答案 0 :(得分:1)

在@ bwarren2提供了一些有用的建议后,我想我在Heroku上使用R,python和rpy2的方式更为清晰。

在这个例子中,我使用的是python buildpack heroku-buildpack-python-sklearn,它包含numpy,scipy和scikit-learn from binary builder。 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实验室的新用户-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,to avoid the problem described here

还将matplotlib == 1.1.0添加到requirements.txt,这是旧版本as described here