close

[Solved] Failing to install psycopg2-binary on new docker container

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Failing to install psycopg2-binary on new docker container in Python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Failing to install psycopg2-binary on new docker container Error Occurs?

Today I get the following error Failing to install psycopg2-binary on new docker container in Python.

How To Solve Failing to install psycopg2-binary on new docker container Error ?

  1. How To Solve Failing to install psycopg2-binary on new docker container Error ?

    To Solve Failing to install psycopg2-binary on new docker container Error 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-get update \
    && apt-get -y install libpq-dev gcc \
    && pip install psycopg2

Solution 1

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 2

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-get update \
    && apt-get -y install libpq-dev gcc \
    && pip install psycopg2

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also Read

Leave a Comment