I'm currently going through djangoforprofessional tutorial and I've been trying to resolve an error related to installing psycopg2 for postgres in a docker container.
After setting up Dockerfile, requirements.txt, and docker-compose.yml which is shown below, I entered this command: docker-compose up -d --build
and the returned output (error) is shown below.
I got the command on StackOverflow but still didn't resolve the issue.
Thank you very much in advance.
#0 23.39 Collecting psycopg2==2.9.5
#0 23.55 Downloading psycopg2-2.9.5.tar.gz (384 kB)
#0 25.11 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 384.3/384.3 kB 246.3 kB/s eta 0:00:00
#0 25.20 Preparing metadata (setup.py): started
#0 26.74 Preparing metadata (setup.py): finished with status 'error'
#0 26.78 error: subprocess-exited-with-error
#0 26.78
#0 26.78 × python setup.py egg_info did not run successfully.
#0 26.78 │ exit code: 1
#0 26.78 ╰─> [25 lines of output]
#0 26.78 /usr/local/lib/python3.12/site-packages/setuptools/config/setupcfg.py:508: SetuptoolsDeprecationWarning: The license_file parameter is deprecated, use license_files instead.
#0 26.78 warnings.warn(msg, warning_class)
#0 26.78 running egg_info
#0 26.78 creating /tmp/pip-pip-egg-info-g5ko86oj/psycopg2.egg-info
#0 26.78 writing /tmp/pip-pip-egg-info-g5ko86oj/psycopg2.egg-info/PKG-INFO
#0 26.78 writing dependency_links to /tmp/pip-pip-egg-info-g5ko86oj/psycopg2.egg-info/dependency_links.txt
#0 26.78 writing top-level names to /tmp/pip-pip-egg-info-g5ko86oj/psycopg2.egg-info/top_level.txt
#0 26.78 writing manifest file '/tmp/pip-pip-egg-info-g5ko86oj/psycopg2.egg-info/SOURCES.txt'
#0 26.78
#0 26.78 Error: pg_config executable not found.
#0 26.78
#0 26.78 pg_config is required to build psycopg2 from source. Please add the directory
#0 26.78 containing pg_config to the $PATH or specify the full executable path with the
#0 26.78 option:
#0 26.78
#0 26.78 python setup.py build_ext --pg-config /path/to/pg_config build ...
#0 26.78
#0 26.78 or with the pg_config option in 'setup.cfg'.
#0 26.78
#0 26.78 If you prefer to avoid building psycopg2 from source, please install the PyPI
#0 26.78 'psycopg2-binary' package instead.
#0 26.78
#0 26.78 For further information please check the 'doc/src/install.rst' file (also at
#0 26.78 <
https://www.psycopg.org/docs/install.html>).
#0 26.78
#0 26.78 [end of output]
#0 26.78
#0 26.78 note: This error originates from a subprocess, and is likely not a problem with pip.
#0 26.78 error: metadata-generation-failed
#0 26.78
#0 26.78 × Encountered error while generating package metadata.
#0 26.78 ╰─> See above for output.
#0 26.78
#0 26.78 note: This is an issue with the package mentioned above, not pip.
#0 26.78 hint: See above for details.
------
failed to solve: executor failed running [/bin/sh -c pip install -r requirements.txt]: exit code: 1