如何修复错误:在 Elastic Beanstalk 上永久找不到 pg_config 可执行文件

Mar*_*tiz 4 django postgresql amazon-ec2 amazon-web-services amazon-elastic-beanstalk

我有一个在 Elastic Beanstalk 上使用 PostgreSQL 的 Django 项目。我在部署时发现了下一个错误:

Error: pg_config executable not found.

pg_config is required to build psycopg2 from source. 

Please add the directory containing pg_config to the $PATH or specify the full executable path with the option:

python setup.py build_ext --pg-config /path/to/pg_config build ...
Run Code Online (Sandbox Code Playgroud)

在弹性 beantalk 上关注了psycopg2 - 无法部署应用程序来解决它并且它起作用了!但是过了一会儿,亚马逊似乎更新了我的虚拟环境,错误又回来了,所以我必须回去一遍又一遍地做同样的事情。

我也尝试过直接从 Elastic Beanstalk 面板配置数据库实例,但没有任何变化。

数据库在 RDS 上,我认为重要的是要说,当我在我的实例上手动安装 psycopg2 并重新部署一切正常时,我什至在此之后进行了几次部署,问题不存在,但经过一段时间后尽管。

我真的很想知道如何一劳永逸地解决它。提前致谢。

abk*_*sta 8

它试图做的是从源代码构建 postgres 驱动程序。您可以通过几种不同的方式来处理这个问题。例如,您可以选择从二进制包安装驱动程序,而不是从源代码构建它们。

在您的 requirements.txt 中,替换

psycopg2==2.8.5
Run Code Online (Sandbox Code Playgroud)

psycopg2-binary==2.8.5
Run Code Online (Sandbox Code Playgroud)

如果在部署到 Beanstalk 时确实坚持从源代码构建它,则需要使用平台挂钩来预安装编译它所需的依赖项。AL2 实例非常简单,因此您需要大致执行以下操作:

  • 添加目录结构 .platform/hooks/prebuild
  • 在预构建中,创建一个脚本,类似于“10_install_dependencies.sh”
  • 在脚本的顶部,您将需要 #!/usr/bin/sh

使用此脚本添加所需的依赖项。例如,对于 posgres 开发库,您将需要

sudo yum install -y <yum-packahe-that-you-need>
Run Code Online (Sandbox Code Playgroud)

您可能最终还必须安装构建 psycopg 所需的其他开发库...