【问题标题】:Heroku RPy RHOME discoveryHeroku RPy RHOME 发现
【发布时间】:2013-05-08 08:07:09
【问题描述】:

我正在尝试运行一个使用 Python 和 R 的 multipack Heroku 应用程序。我首先安装了 R,但是尽管我对 $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

【问题讨论】:

  • rpy2 的setup.py 正在使用os.popen("R RHOME")。在 Heroku 上创建子子进程时,可能正在发生“某些事情”。由于该函数在 Python 中已弃用,因此值得尝试 subprocess 模块是否解决了该问题。
  • 原来问题是 buildpack 安装在 heroku 上是事务性的,因此 $PATH 在安装之间发生变化。分叉 heroku python buildpack 并调整 $PATH 变量使安装运行,但我稍后会遇到更新和更有趣的导入错误。随着它的发展,更多。
  • 搞定了!这比您最初预期的要复杂得多,需要修改几个自定义构建包和配置环境变量来管理导入。不过,秘诀在于 Heroku 构建包是事务性的。
  • 如果您发现 rpy2 安装过程可以改进的地方,请不要犹豫提出建议(或提供补丁)。

标签: heroku


【解决方案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,to avoid the problem described here

还在 requirements.txt 中添加了 matplotlib==1.1.0,这是一个旧版本 as described here

【讨论】:

  • 就我而言,我必须将这两个路径添加到 LD_LIBRARY_PATH 中:/app/vendor/.apt/usr/lib/libblas/:/app/vendor/.apt/usr/lib/
猜你喜欢
  • 2012-04-19
  • 2012-09-21
  • 2012-01-23
  • 2014-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-26
  • 1970-01-01
相关资源
最近更新 更多