Why is installing python-psycopg2 on my Docker image not preventing the subsequent “No module named ‘psycopg2′” error?

I don’t think you even need to have RUN apt-get install -y python-psycopg2. You already have RUN apt-get install -y libpq-dev.

I think you forgot to put psycopg2==2.8.6 inside your requirements.txt file. Your Dockerfile could change to:

FROM python:3.8-slim
RUN apt-get update && apt-get install

RUN apt-get install -y \
  dos2unix \
  libpq-dev \
  libmariadb-dev-compat \
  libmariadb-dev \
  gcc \
  && apt-get clean

RUN python -m pip install --upgrade pip

WORKDIR /my-app/

COPY requirements.txt requirements.txt
COPY entrypoint.sh entrypoint.sh
RUN python -m pip install -r requirements.txt

RUN dos2unix /my-app/entrypoint.sh

ENTRYPOINT ["bash", "/my-app/entrypoint.sh"]

And make sure you have this in requirements.txt


Btw, you are using both MariaDB and PostgreSQL in the same project?

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top