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:
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 . .
This is my docker-compose-yml:
version: '3.8'
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
When I run "docker-compose build", every package before psycopg2 is installed fine, but when psycopg2 turn comes, I get this nasty error:
ERROR: Command errored out with exit status 1:
command: /usr/local/bin/python3 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-aapmzhr4/psycopg2_ae1db2bf32854633b7d62f111940d39b/setup.py'"'"'; __file__='"'"'/tmp/pip-install-aapmzhr4/psycopg2_ae1db2bf32854633b7d62f111940d39b/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' 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
<https://www.psycopg.org/docs/install.html>).
----------------------------------------
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:>=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
I have read this stack post, and I have tried this, this and this. None worked. I am using python 3.6.9, and my psycopg2 version is 2.9.2
What can I do?