Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix Error: pg_config executable not found on Elastic Beanstalk permanently

I have a Django project that works with PostgreSQL on Elastic Beanstalk. I have found the next error when deploying:

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 ...

I followed psycopg2 on elastic beanstalk - can't deploy app to solve it and it worked! BUT after a while Amazon seems to update my virtual env and the error returns so I have to go back and do the same stuff over and over again.

I also have tried configuring the database instance directly from the Elastic Beanstalk panel but nothing changes.

The database is on RDS and I think it's important to say that when I manually install psycopg2 on my instance and re-deploy everything works fine, I even have made a couple of deploys after that and the problems is not there but it is after a while.

I really want to know how to solve it once for all. Thanks in advance.

like image 337
Mario Ortiz Avatar asked Jan 01 '23 18:01

Mario Ortiz


1 Answers

It is trying to do is build the postgres drivers from source. You can deal with this several different ways. For example, you can choose to install the drivers from a binary package instead of building them from source.

in your requirements.txt, replace

psycopg2==2.8.5

with

psycopg2-binary==2.8.5

If, you do insist on building it from source when you deploy to Beanstalk, you will need to use platform hooks to pre-install the dependencies that are needed to compile it. The AL2 instances are pretty bare-bone, so you will need to do roughly the following:

  • add directory structure .platform/hooks/prebuild
  • in prebuild, create a script, something like '10_install_dependencies.sh'
  • at the top of the script you will need #!/usr/bin/sh

Use this script to add needed dependencies. For example, for the posgres development libs you will want

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

You may also end up having to install other development libs needed to build psycopg...

like image 102
abkonsta Avatar answered Jan 13 '23 13:01

abkonsta