Heroku RPy RHOME发现酒店
我正在尝试运行一个使用Python和R的多包Heroku应用程序。我让multi-buildpack先安装R,但尽管我修改了$PATH,RPy的安装还是找不到R。这是怎么回事?当init.R运行时,R将RHOME视为“/app/vendor/R/lib64/R”Heroku RPy RHOME发现酒店,heroku,Heroku,我正在尝试运行一个使用Python和R的多包Heroku应用程序。我让multi-buildpack先安装R,但尽管我修改了$PATH,RPy的安装还是找不到R。这是怎么回事?当init.R运行时,R将RHOME视为“/app/vendor/R/lib64/R” -----> Fetching custom git buildpack... done -----> Multipack app detected =====> Downloading Buildpack: http
-----> 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
在@bwarren2提供了一些有用的建议之后,我想我有了一种更简洁的方法,可以在Heroku上同时使用R、python和rpy2 在本例中,我使用的是PythonBuildPack heroku buildpack python sklearn,它包含从二进制构建中学习的numpy、scipy和scikit。Rpy2库具有很好的numpy集成,因此您可能希望从这个开始。如果不是,那么同样的方法也适用于普通的python构建包 创建一个.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构建包需要知道R和一些库安装在哪里。Heroku上的slug构建系统不会将R构建包中设置的所有环境变量传递给python构建包
但是,我们可以使用Heroku实验室的新用户环境编译功能,并显式地为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_路径更新为包含/usr/lib和/usr/local/lib
还将matplotlib==1.1.0添加到requirements.txt,这是一个较旧的版本。rpy2的
setup.py
正在使用os.popen(“RHOME”)
。在Heroku上创建子进程时,可能发生了“某些事情”。由于Python中不推荐使用该函数,因此值得尝试一下子流程
模块是否解决了该问题。事实证明,问题在于buildpack安装在heroku上是事务性的,因此$PATH在安装之间发生了变化。分叉heroku python buildpack并调整$PATH变量可以使安装运行,但稍后我会遇到更新且更有趣的导入错误。随着时间的推移会越来越多,完成了!这比您最初预期的要复杂得多,黑客攻击了几个自定义构建包,并配置了环境变量来管理导入。秘密在于Heroku buildpacks是事务性的。如果您看到rpy2安装过程可以改进的地方,请毫不犹豫地提出建议(或提供补丁)。在我的情况下,我必须将这两个路径添加到LD_LIBRARY_PATH:/app/vendor/.apt/usr/libblas/:/app/vendor/.apt/usr/lib中/