To solve Failing to install psycopg2-binary on new docker container follow any of the below methods.
Contents
Error log
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 ...
How to solve Failing to install psycopg2-binary on new docker container ?
Method 1:
You can modify the docker file with the code below to solve it.
FROM python:3.8.3-slim #you can also use Image python:3.9.5-slim or 3.9.5-slim-buster
RUN apt-get update \
&& apt-get -y install libpq-dev gcc \
&& pip install psycopg2
Method 2 :
Even though a pre-compiled binary wheel is available on PyPI
, you will need to compile all packages on Alpine Linux. So, modify your base image to python:3.8.3-slim-buster
or python:3.8-slim-buster
and you should be good to go.
Similar Errors:
pipenv requires python 3.7 but installed version is 3.8 and won’t install