如何在Heroku上安装libpq?

时间:2019-03-16 01:54:38

标签: r postgresql heroku

因此,我已经能够部署应该包含我的RScript的Heroku APP:init.Raccess_heroku.R

我的主要目标是测试如何在Heroku上保存和访问数据库,以便查询并绘制一些图表(将来很有可能在ShinyApp中使用)。

因此,我也通过才华横溢的人发现了这个要点:@hrbrmstr

https://gist.github.com/hrbrmstr/45c67103a9728f59212cd13262adca74

这是另一本有关如何通过init.R脚本在Heroku中安装软件包的教程。

https://www.r-bloggers.com/running-an-r-script-on-heroku/

init.R

my_packages <- c("processx","RPostgres","httr", "dbplyr", "tidyverse")
install_if_missing <- function(p) {
  if(p %in% rownames(installed.packages())==FALSE){
    install.packages(p)}
}

invisible(sapply(my_packages, install_if_missing))

不幸的是,当部署到heroku时,出现此错误,提示未找到libpq,因此无法安装RPostgres

Heroku-APP网址:https://blooming-waters-73325.herokuapp.com/

remote:        * installing *source* package ‘RPostgres’ ...
    remote:        ** package ‘RPostgres’ successfully unpacked and MD5 sums checked
    remote:        Using PKG_CFLAGS=
    remote:        Using PKG_LIBS=-lpq
    remote:        ------------------------- ANTICONF ERROR ---------------------------
    remote:        Configuration failed because libpq was not found

如下所示,它为您提供有关如何在不同系统上安装libpq的说明。我不知道我的heroku应用程序部署在哪个“系统”中,所以我不知道要实现什么选项以及如何实现?

我应该把它放在init.R中吗?

remote: -----> R Console app detected
remote: -----> Vendoring R 3.4.4 for heroku-16 stack (latest)
remote:        Retrieving R binaries from cache
remote: -----> Executing R init script
remote:        Installing package into ‘/usr/local/lib/R/site-library’
remote:        (as ‘lib’ is unspecified)
remote:        trying URL 'https://cloud.r-project.org/src/contrib/RPostgres_1.1.1.tar.gz'
remote:        Content type 'application/x-gzip' length 44803 bytes (43 KB)
remote:        ==================================================
remote:        downloaded 43 KB
remote:
remote:        * installing *source* package ‘RPostgres’ ...
remote:        ** package ‘RPostgres’ successfully unpacked and MD5 sums checked
remote:        Using PKG_CFLAGS=
remote:        Using PKG_LIBS=-lpq
remote:        ------------------------- ANTICONF ERROR ---------------------------
remote:        Configuration failed because libpq was not found. Try installing:
remote:         * deb: libpq-dev (Debian, Ubuntu, etc)
remote:         * rpm: postgresql-devel (Fedora, EPEL)
remote:         * rpm: postgreql8-devel, psstgresql92-devel, postgresql93-devel, or postgresql94-devel (Am
azon Linux)
remote:         * csw: postgresql_dev (Solaris)
remote:         * brew: libpq (OSX)
remote:        If libpq is already installed, check that either:
remote:        (i)  'pkg-config' is in your PATH AND PKG_CONFIG_PATH contains
remote:             a libpq.pc file; or
remote:        (ii) 'pg_config' is in your PATH.
remote:        If neither can detect , you can set INCLUDE_DIR
remote:        and LIB_DIR manually via:
remote:        R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
remote:        --------------------------------------------------------------------
remote:        ERROR: configuration failed for package ‘RPostgres’
remote:        * removing ‘/usr/local/lib/R/site-library/RPostgres’
remote:
remote:        The downloaded source packages are in
remote:         ‘/tmp/RtmpZjXuPF/downloaded_packages’
remote:        Warning message:
remote:        In install.packages(p) :
remote:          installation of package ‘RPostgres’ had non-zero exit status
remote:        R 3.4.4 successfully installed (with init)

最后,我想将虹膜数据集托管在Heroku上,并可以对其进行查询以显示一些图。我的脚本只在最后打印出来,但是没关系,因为我知道如何使用ggplot2进行打印。

更新1:

由于克里斯的回答,我能够安装libpq-dev,但是现在出现了此错误:

remote:        Processing triggers for libc-bin (2.23-0ubuntu10) ...
    remote:        Processing triggers for man-db (2.7.5-1) ...
    remote:        /usr/bin/mandb: error while loading shared libraries: libmandb-2.7.5.so: cannot open shared

因此,根据克里斯的回答,我将libman放在了Aptfile上,但现在我得到了:

remote: -----> Installing binary dependencies from Aptfile
remote: Reading package lists...
remote: Building dependency tree...
remote: Reading state information...
remote: E: Unable to locate package libmandb-2.7.5
remote: E: Couldn't find any package by glob 'libmandb-2.7.5'
remote: E: Couldn't find any package by regex 'libmandb-2.7.5'
remote: -----> Executing R init script

我该怎么办?

Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 371 bytes | 123.00 KiB/s, done.
Total 4 (delta 1), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> R Console app detected
remote: -----> Vendoring R 3.4.4 for heroku-16 stack (latest)
remote:        Retrieving R binaries from cache
remote: -----> Installing binary dependencies from Aptfile
remote:        Reading package lists...
remote:        Building dependency tree...
remote:        Reading state information...
remote:        E: Unable to locate package libmandb-2.7.5
remote:        E: Couldn't find any package by glob 'libmandb-2.7.5'
remote:        E: Couldn't find any package by regex 'libmandb-2.7.5'
remote: -----> Executing R init script
remote:        R 3.4.4 successfully installed (with init)
remote: -----> Caching build outputs
remote:        Build took 68 seconds to complete
remote: -----> Discovering process types
remote:        Procfile declares types     -> (none)
remote:        Default types for buildpack -> console
remote:
remote: -----> Compressing...
remote:        Done: 311.2M
remote: -----> Launching...
remote:  !     Warning: Your slug size exceeds our soft limit (311 MB) which may affect boot time.
remote:        Released v9
remote:        https://blooming-waters-73325.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/blooming-waters-73325.git
   79635e7..4fcab2b  master -> master

1 个答案:

答案 0 :(得分:2)

尝试在包含以下内容的存储库的根目录中包含一个名为Aptfile的文件

libpq-dev

这是错误消息建议安装的Ubuntu软件包的名称。下次部署时,您正在使用should install the package for you的R buildpack。