Skip to content Skip to sidebar Skip to footer

Failing To Install Psycopg2-binary On New Docker Container

I have encountered a problem while trying to run my django project on a new Docker container. It is my first time using Docker and I can't seem to find a good way to run a django p

Solution 1:

I made it work. This is the code:

FROM python:3.8.3-slim #Image python:3.9.5-slim also works # Image python:3.9.5-slim-buster also works

RUN apt-getupdate \
    && apt-get-y install libpq-dev gcc \
    && pip install psycopg2
    

Solution 2:

On Alpine Linux, you will need to compile all packages, even if a pre-compiled binary wheel is available on PyPI. On standard Linux-based images, you won't (https://pythonspeed.com/articles/alpine-docker-python/ - there are also other articles I've written there that might be helpful, e.g. on security).

So change your base image to python:3.8.3-slim-buster or python:3.8-slim-buster and it should work.

Solution 3:

This scripts work on MacBook Air M1

Dockerfile

FROM ubuntu:20.04
RUN apt-getupdate&& apt-get-y install libpq-dev gcc && pip install psycopg2
COPY requirements.txt /cs_account/
RUN pip3 install -r requirements.txt

requirements.txt

psycopg2-binary~=2.8.6

Updated answer from the answer of Zoltán Buzás

Solution 4:

This worked for me. Try slim-buster image.

In your Dockerfile

FROM python:3.8.7-slim-buster

and in your requirements.txt file

psycopg2-binary~= <<version_number>>

Solution 5:

I've made a custom image with

FROM python:alpine
ADD requirements.txt /
RUN apk update--no-cache \&& apk add build-base postgresql-dev libpq --no-cache --virtual .build-deps \&& pip install --no-cache-dir --upgrade pip \&& pip install --no-cache-dir -r /requirements.txt \&& apk del .build-deps
RUN apk add postgresql-libs libpq --no-cache

and requirements.txt

django
djangorestframework
psycopg2-binary

Post a Comment for "Failing To Install Psycopg2-binary On New Docker Container"