6

Please how should i install psycopg2-binary on my python image.

I tried pip install psycopg2-binary==2.8.2 but i got this error

ERROR: Could not find a version that satisfies the requirement psycopg2-binary==2.8.2 (from versions: 2.7.4, 2.7.5, 2.7.6, 2.7.6.1, 2.7.7, 2.8, 2.8.1, 2.8.2, 2.8.3, 2.8.4, 2.8.5, 2.8.6, 2.9, 2.9.1) ERROR: No matching distribution found for psycopg2-binary==2.8.2

My image is python3.9-alpine

What should i do please???

charles
  • 209
  • 3
  • 10

1 Answers1

4

Given the amount of work that requires to be done, I suggest you use a different base image, e.g. python:3.9 or that you install the alpine package py3-psycopg2 (which is on v 2.8.6 at the time of writing).

Anyway I tried it on my machine and in the error it's also written Error: pg_config executable not found.

The pg_config is part of the postgres_dev package and needs to be installed before installing the psycopg2-binary package.

The psycopg2-binary will also need the gcc to be installed and some other libraries.

In other words, you have to execute the following commands:

apk add postgresql-dev gcc ...
pip install psycopg2-binary==2.8.2

I've abandoned the topic after I had to install a bunch of libraries.

Stefano
  • 4,730
  • 1
  • 20
  • 28
  • Hello @Stefano ! Thank you for your help . I got this error **apk not found** when trying this line apk add postgresql-dev gcc ... i think because its debian distribution – charles Aug 25 '21 at 14:17
  • just to be on the same page. I've executed the following: `docker run -it --rm python:3.9-alpine sh`. Once inside the container, I've executed `apk add postgresql-dev gcc`. As I wrote in the answer, the list is not complete. There's quite an amount of libraries to install as well – Stefano Aug 25 '21 at 14:20
  • did the same and got this error **bash: apk: command not found** – charles Aug 25 '21 at 14:22
  • I don't think you did. Alpine comes without `bash`. You would not get that error. – Stefano Aug 25 '21 at 14:24
  • it's not an alpine distribution ? Am i wrong.? – charles Aug 25 '21 at 14:24
  • e.g. if I execute `docker run -it --rm python:3.9-alpine bash`, I receive `docker: Error response from daemon: OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"bash\": executable file not found in $PATH": unknown.` – Stefano Aug 25 '21 at 14:25
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/236408/discussion-between-stefano-and-charles). – Stefano Aug 25 '21 at 14:26