Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1.4K
Vistas
psycopg2 installation for python:2.7-alpine in Docker

To use PostgreSql in python I need to

pip install psycopg2   

However, it has dependency on libpq-dev and python-dev. I wonder how can I install the dependencies in alpine? Thanks.

Here is a Dockerfile:

FROM python:2.7-alpine

RUN apk add python-dev libpq-dev
RUN pip install psycopg2

and the output is:

Step 3 : RUN apk add python-dev libpq-dev ---> Running in 3223b1bf7cde WARNING: Ignoring APKINDEX.167438ca.tar.gz: No such file or directory WARNING: Ignoring APKINDEX.a2e6dac0.tar.gz: No such file or directory ERROR: unsatisfiable constraints: libpq-dev (missing): required by: world[libpq-dev] python-dev (missing): required by: world[python-dev] ERROR: Service 'service' failed to build: The command '/bin/sh -c apk add python-dev libpq-dev' returned a non-zero code: 2

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

If you only need to install psycopg2 for python 2.7 on Docker image based on python:2.7-alpine then following code for Dockerfile will be nice for you:

FROM python:2.7-alpine

RUN apk update && \
    apk add --virtual build-deps gcc python-dev musl-dev && \
    apk add postgresql-dev

RUN pip install psycopg2
over 4 years ago · Santiago Trujillo Denunciar

0

An explanation before compile/install psycopg2

  • libpq is the client library for PostgreSQL
  • postgresql-dev are the package with the source headers to link libpq in a library/binary in a compilation, in this case when pip compiles psycopg .

I use the following configuration in alpine 3.7, I add some comments to explain it.

# Installing client libraries and any other package you need
RUN apk update && apk add libpq

# Installing build dependencies
# For python3 you need to add python3-dev *please upvote the comment
# of @its30 below if you use this*
RUN apk add --virtual .build-deps gcc python-dev musl-dev postgresql-dev

# Installing and build python module
RUN pip install psycopg2

# Delete build dependencies
RUN apk del .build-deps
over 4 years ago · Santiago Trujillo Denunciar

0

Had problems with running Python 3.7 and PostgreSQL under Alpine Linux in Docker. This article helped https://www.rockyourcode.com/install-psycopg2-binary-with-docker/

The main thing is to reference psypcopg2-binary in your requirements file and install the following packages (in Dockerfile):

RUN apk update && \
apk add --no-cache --virtual build-deps gcc python3-dev musl-dev && \
apk add postgresql-dev
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda