r - 如何在 Heroku 上安装 libpq?

标签 r postgresql heroku

因此,我已经能够部署一个应该包含我的 RScripts 的 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/

初始化.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 上托管 iris 数据集,并有可能查询它以显示一些图。我的脚本只在最后打印它,但没关系,因为我知道如何使用 ggplot2 绘图。

更新 1:

感谢 Chris 的回答,我能够安装 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

因此,根据 Chris 的回答,我将 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

最佳答案

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

libpq-dev

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

关于r - 如何在 Heroku 上安装 libpq?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55192742/

相关文章:

r - R 中 (x,y) 点周围正态分布的 3D 图

r - 从R中的文件读取数据帧时如何跳过无效行?

R:组合两个不等长的矩阵/向量,根据相同的值匹配行

python - 将 QPixmap 保存到 PostgreSQL 而不使用准备好的查询

sql - Postgres : Get which part is a record within a set

postgresql - 致命 : could not access private key file “/etc/ssl/private/ssl-cert-snakeoil.key” : Permission denied

python - RabbitMQ 上的预定 Celery 任务在指定的运行时间后仍未得到确认

r - ggplot2 和其他函数之间的加号 (R)

node.js - Express 服务的 Vuejs 前端和 Node 安全实践中的后端 API

git - Heroku 应用程序的运行时可以知道它的提交 ID 吗?