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

Django 如何修复错误:在Elastic Beanstalk上找不到pg_config可执行文件,django,postgresql,amazon-web-services,amazon-ec2,amazon-elastic-beanstalk,Django,Postgresql,Amazon Web Services,Amazon Ec2,Amazon Elastic Beanstalk,我有一个Django项目,它与PostgreSQL一起在Elastic Beanstalk上工作。 我在部署时发现了下一个错误: 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

我有一个Django项目,它与PostgreSQL一起在Elastic Beanstalk上工作。 我在部署时发现了下一个错误:

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 ...
我跟着解决了它,它成功了!但是过了一段时间,Amazon似乎更新了我的虚拟环境,错误又回来了,所以我不得不回去一遍又一遍地做同样的事情

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

数据库在RDS上,我认为重要的一点是,当我在实例上手动安装psycopg2并重新部署时,一切正常,我甚至在那之后进行了几次部署,问题并不存在,但过了一段时间就出现了


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

它正在尝试从源代码构建postgres驱动程序。 你可以用几种不同的方法来处理这个问题。例如,您可以选择从二进制软件包安装驱动程序,而不是从源代码构建驱动程序

在requirements.txt中,替换

psycopg2==2.8.5

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

  • 添加目录结构。platform/hooks/prebuild
  • 在预构建中,创建一个脚本,类似于“10_install_dependencies.sh”
  • 在脚本的顶部,您需要#/usr/bin/sh
使用此脚本添加所需的依赖项。例如,对于您想要的posgres开发库

sudo yum install -y <yum-packahe-that-you-need>
sudo yum安装-y

您可能还需要安装构建psycopg所需的其他开发lib…

看看这个答案:非常感谢;使用
psycopg2二进制文件
效果很好
sudo yum install -y <yum-packahe-that-you-need>