⏱️ 3 min read📅 2026-06-04

How to Fix: Error: pg_config executable not found when installing psycopg2 on Alpine in Docker

Quick Answer: The issue is caused by the missing pg_config executable. To fix this, you can install the postgresql-client package which includes pg_config.

When installing psycopg2 on Alpine in Docker, an error can occur due to the inability to find the pg_config executable. This issue affects users who are trying to connect to an AWS RDS instance of Postgres using their Flask app within a Docker container.

This error can be frustrating as it prevents the installation process from completing successfully. However, by following the steps outlined in this guide, you should be able to resolve the issue and continue with your application.

⚠️ Common Causes

  • The primary reason for this error is that the pg_config executable is not available on Alpine Linux. This is because pg_config is a system-level tool required for building PostgreSQL extensions.
  • Another possible cause could be the Docker image not being properly configured to include the necessary dependencies for psycopg2.

✅ Best Solutions to Fix It

Installing the necessary dependencies

  1. Step 1: Step 1: Update the Docker image to include the necessary dependencies. You can do this by adding the following line to your Dockerfile: RUN apk add --no-cache libpq-dev
  2. Step 2: Step 2: After updating the Docker image, try running the pip install command again to see if the error persists.
  3. Step 3: Step 3: If the issue still occurs, you may need to reinstall the Docker image or modify the Dockerfile to include additional dependencies.

Configuring the environment variables

  1. Step 1: Step 1: Set the PG_CONFIG and LD_LIBRARY_PATH environment variables in your Docker container. You can do this by adding the following lines to your Dockerfile: ENV PG_CONFIG=/usr/lib/postgresql/13/bin/pg_config ENV LD_LIBRARY_PATH=-L/usr/lib/postgresql/13/lib
  2. Step 2: Step 2: After setting the environment variables, try running the pip install command again to see if the error persists.
  3. Step 3: Step 3: If the issue still occurs, you may need to modify the environment variables or reinstall the Docker image.

✨ Wrapping Up

By following these steps, you should be able to resolve the error and successfully install psycopg2 on Alpine in Docker. Remember to regularly update your Docker images and configuration to ensure that your application continues to function smoothly.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions