title: Error: pg_config executable not found, when installing for docker-compose
body: <p>I have a Django application in a virtualenv, and I use psycopg2 in it for PostgreSQL connection. I have it installed in venv and it works well. I want to docker-ize my application. I have made a requirements.txt with pip freeze. This is my Dockerfile:</p>
  <pre><code>FROM python:3.9.6-alpine
  
  WORKDIR /usr/src/app
  
  ENV PYTHONDONTWRITEBYTECODE 1
  ENV PYTHONUNBUFFERED 1
  
  RUN python3 -m pip install --upgrade pip
  COPY ./requirements.txt .
  RUN python3 -m pip install -r requirements.txt 
  
  COPY . .
  </code></pre>
  <p>This is my docker-compose-yml:</p>
  <p>version: '3.8'</p>
  <pre><code>services:
    web:
      build: .
      command: python3 manage.py runserver 0.0.0.0:8000
      volumes:
        - ./app/:/usr/src/app/
      ports:
        - 8000:8000
      env_file:
        - ./.env.dev
  </code></pre>
  <p>When I run &quot;docker-compose build&quot;, every package before psycopg2 is installed fine, but when psycopg2 turn comes, I get this nasty error:</p>
  <pre><code>ERROR: Command errored out with exit status 1:
     command: /usr/local/bin/python3 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '&quot;'&quot;'/tmp/pip-install-aapmzhr4/psycopg2_ae1db2bf32854633b7d62f111940d39b/setup.py'&quot;'&quot;'; __file__='&quot;'&quot;'/tmp/pip-install-aapmzhr4/psycopg2_ae1db2bf32854633b7d62f111940d39b/setup.py'&quot;'&quot;';f = getattr(tokenize, '&quot;'&quot;'open'&quot;'&quot;', open)(__file__) if os.path.exists(__file__) else io.StringIO('&quot;'&quot;'from setuptools import setup; setup()'&quot;'&quot;');code = f.read().replace('&quot;'&quot;'\r\n'&quot;'&quot;', '&quot;'&quot;'\n'&quot;'&quot;');f.close();exec(compile(code, __file__, '&quot;'&quot;'exec'&quot;'&quot;'))' egg_info --egg-base /tmp/pip-pip-egg-info-y2w1hroe
         cwd: /tmp/pip-install-aapmzhr4/psycopg2_ae1db2bf32854633b7d62f111940d39b/
    Complete output (23 lines):
    running egg_info
    creating /tmp/pip-pip-egg-info-y2w1hroe/psycopg2.egg-info
    writing /tmp/pip-pip-egg-info-y2w1hroe/psycopg2.egg-info/PKG-INFO
    writing dependency_links to /tmp/pip-pip-egg-info-y2w1hroe/psycopg2.egg-info/dependency_links.txt
    writing top-level names to /tmp/pip-pip-egg-info-y2w1hroe/psycopg2.egg-info/top_level.txt
    writing manifest file '/tmp/pip-pip-egg-info-y2w1hroe/psycopg2.egg-info/SOURCES.txt'
    
    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 ...
    
    or with the pg_config option in 'setup.cfg'.
    
    If you prefer to avoid building psycopg2 from source, please install the PyPI
    'psycopg2-binary' package instead.
    
    For further information please check the 'doc/src/install.rst' file (also at
    &lt;https://www.psycopg.org/docs/install.html&gt;).
    
    ----------------------------------------
  WARNING: Discarding https://files.pythonhosted.org/packages/33/ed/79434011d773e5ea4c51262f6ebfb86680c2908d7677f31ebccd5aa9f1b3/psycopg2-2.9.2.tar.gz#sha256=a84da9fa891848e0270e8e04dcca073bc9046441eeb47069f5c0e36783debbea (from https://pypi.org/simple/psycopg2/) (requires-python:&gt;=3.6). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
  ERROR: Could not find a version that satisfies the requirement psycopg2==2.9.2 (from versions: 2.0.10, 2.0.11, 2.0.12, 2.0.13, 2.0.14, 2.2.0, 2.2.1, 2.2.2, 2.3.0, 2.3.1, 2.3.2, 2.4, 2.4.1, 2.4.2, 2.4.3, 2.4.4, 2.4.5, 2.4.6, 2.5, 2.5.1, 2.5.2, 2.5.3, 2.5.4, 2.5.5, 2.6, 2.6.1, 2.6.2, 2.7, 2.7.1, 2.7.2, 2.7.3, 2.7.3.1, 2.7.3.2, 2.7.4, 2.7.5, 2.7.6, 2.7.6.1, 2.7.7, 2.8, 2.8.1, 2.8.2, 2.8.3, 2.8.4, 2.8.5, 2.8.6, 2.9, 2.9.1, 2.9.2)
  ERROR: No matching distribution found for psycopg2==2.9.2
  </code></pre>
  <p>I have read <a href="https://stackoverflow.com/questions/11618898/pg-config-executable-not-found">this</a> stack post, and I have tried <a href="https://stackoverflow.com/a/69440588/13089078">this</a>, <a href="https://stackoverflow.com/a/58984045/13089078">this</a> and <a href="https://stackoverflow.com/a/64042538/13089078">this</a>. None worked. I am using python 3.6.9, and my psycopg2 version is 2.9.2</p>
  <p>What can I do?</p>