2

I'm having issues installing Psycopg3 in a Docker image with python 3.7.3, pip 22.0.4 and CentOS Linux release 7.8.2003 (Core).

When I run pip install psycopg[binary] I get the following messages and errors:

Collecting psycopg[binary]
Downloading psycopg-3.0.12-py3-none-any.whl (143 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 143.1/143.1 KB 5.6 MB/s eta 0:00:00
Collecting typing-extensions>=3.10
  Downloading typing_extensions-4.2.0-py3-none-any.whl (24 kB)
Collecting backports.zoneinfo>=0.2.0
  Downloading backports.zoneinfo-0.2.1-cp37-cp37m-manylinux1_x86_64.whl (70 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 70.7/70.7 KB 16.9 MB/s eta 0:00:00
Collecting psycopg[binary]
  Downloading psycopg-3.0.11-py3-none-any.whl (143 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 143.0/143.0 KB 15.5 MB/s eta 0:00:00
  Downloading psycopg-3.0.10-py3-none-any.whl (142 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 142.1/142.1 KB 23.0 MB/s eta 0:00:00
  Downloading psycopg-3.0.9-py3-none-any.whl (141 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 141.8/141.8 KB 26.9 MB/s eta 0:00:00
  Downloading psycopg-3.0.8-py3-none-any.whl (142 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 142.2/142.2 KB 28.6 MB/s eta 0:00:00
  Downloading psycopg-3.0.7-py3-none-any.whl (141 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 141.7/141.7 KB 21.5 MB/s eta 0:00:00
  Downloading psycopg-3.0.6-py3-none-any.whl (141 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 141.7/141.7 KB 25.3 MB/s eta 0:00:00
  Downloading psycopg-3.0.5-py3-none-any.whl (141 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 141.1/141.1 KB 36.5 MB/s eta 0:00:00
  Downloading psycopg-3.0.4-py3-none-any.whl (140 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 140.9/140.9 KB 25.8 MB/s eta 0:00:00
  Downloading psycopg-3.0.3-py3-none-any.whl (140 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 141.0/141.0 KB 39.9 MB/s eta 0:00:00
  Downloading psycopg-3.0.2-py3-none-any.whl (140 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 140.9/140.9 KB 19.8 MB/s eta 0:00:00
  Downloading psycopg-3.0.1-py3-none-any.whl (140 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 140.6/140.6 KB 31.6 MB/s eta 0:00:00
  Downloading psycopg-3.0-py3-none-any.whl (140 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 140.8/140.8 KB 31.8 MB/s eta 0:00:00
ERROR: Cannot install psycopg[binary]==3.0, psycopg[binary]==3.0.1,    psycopg[binary]==3.0.10, psycopg[binary]==3.0.11, psycopg[binary]==3.0.12, psycopg[binary]==3.0.2, psycopg[binary]==3.0.3, psycopg[binary]==3.0.4, psycopg[binary]==3.0.5, psycopg[binary]==3.0.6, psycopg[binary]==3.0.7, psycopg[binary]==3.0.8 and psycopg[binary]==3.0.9 because these package versions have conflicting dependencies.

The conflict is caused by:
    psycopg[binary] 3.0.12 depends on psycopg-binary==3.0.12; extra == "binary"
    psycopg[binary] 3.0.11 depends on psycopg-binary==3.0.11; extra == "binary"
    psycopg[binary] 3.0.10 depends on psycopg-binary==3.0.10; extra == "binary"
    psycopg[binary] 3.0.9 depends on psycopg-binary==3.0.9; extra == "binary"
    psycopg[binary] 3.0.8 depends on psycopg-binary==3.0.8; extra == "binary"
    psycopg[binary] 3.0.7 depends on psycopg-binary==3.0.7; extra == "binary"
    psycopg[binary] 3.0.6 depends on psycopg-binary==3.0.6; extra == "binary"
    psycopg[binary] 3.0.5 depends on psycopg-binary==3.0.5; extra == "binary"
    psycopg[binary] 3.0.4 depends on psycopg-binary==3.0.4; extra == "binary"
    psycopg[binary] 3.0.3 depends on psycopg-binary==3.0.3; extra == "binary"
    psycopg[binary] 3.0.2 depends on psycopg-binary==3.0.2; extra == "binary"
    psycopg[binary] 3.0.1 depends on psycopg-binary==3.0.1; extra == "binary"
    psycopg[binary] 3.0 depends on psycopg-binary==3.0; extra == "binary"

To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict

ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts

Any ideas on how to fix this? I upgraded python to 3.8 but still didn't fix it. I also tried pip install psycopg[binary]==3.0.12 but that only reduced the number of packages downloaded and the errors to only 3.0.12.

I can't use psycopg2 because I want to use the asyncio classes in psycopg3.

Dula
  • 1,404
  • 1
  • 14
  • 29
  • Did you use `sudo`? If it has to install the Postgres client software, it may need to write to `/usr/local/bin.` – Tim Roberts May 05 '22 at 22:10
  • It's a Docker image and logged in as `USER root` – Dula May 05 '22 at 22:13
  • I've confirmed the problem, and this isn't [the first report of this issue](https://stackoverflow.com/questions/71334162/cannot-pip-install-psycopg-3-on-ec2-centos). Not sure what the resolution is, though. – larsks May 05 '22 at 22:23
  • yeah, I saw that. But that poster was able to use psycopg2 whereas I don't want to because I want to use psycopg3 for the asyncio classes. – Dula May 05 '22 at 22:24
  • I also get cranky messages when doing `sudo pip install psycopg[binary]` on Ubuntu 20.04 / pip 20.02/ python 3.8. However, `sudo pip install psycopg` worked fine. Is there any reason for using that binary extra-flag? Then I thought it was a message about the pip resolver, which has been changed lately, so I updated to pip 22.04 and both `pip install psycopg[binary]` and `pip install psycopg` worked fine. – JL Peyret May 05 '22 at 23:15
  • 2
    I believe that installing `psycopg[binary]` package install the pre-built binary module, while installing `psycopg` may require building the extension from source (which means it needs a compiler, postgres libraries, python libraries, etc available). I'm not sure how `pip` matches binary modules to a distribution, but CentOS 7 ships with Python 2.7 (and 3.6 in EPEL), so maybe there simply is no compatible binary module for your python 3.7 image. – larsks May 05 '22 at 23:27
  • Hmmmm. I *thought* pip wheels were binary already. Not saying you’re wrong but I’d shoot to see if skipping `[binary]` installed and *worked* before I’d downgrade to pg2. The reason I’m saying this is the message almost looks like a packaging/dependency resolution issue rather than a build/install error. – JL Peyret May 05 '22 at 23:49
  • Not sure this will make things any clearer, but... From https://pypi.org/project/psycopg-binary/ : *This distribution contains the precompiled optimization package psycopg_binary* So what this seems to be doing is installing some nifty all-in-C optimization and it is correct to use [binary] to bring it in. But... it also goes on to say *This package is not available for every platform: check out Binary installation in the documentation.* Now if you search for "psycopg binary docker" you get some a number of hits where something else had to be apt installed (Centos will be different). – JL Peyret May 06 '22 at 00:08
  • For example. https://stackoverflow.com/questions/62715570/failing-to-install-psycopg2-binary-on-new-docker-container So, if you really want to do the psycopg[binary] thing, I'd do : 1. `pip install psycopg-binary` and manually fix what pops up as errors by "installing stuff for the compiler" if needed. then 2. `pip install psycopg[binary]`. At that point the psycopg pip will see the psycopg-binary dependency is already installed and will not try to install it. – JL Peyret May 06 '22 at 00:14
  • @JLPeyret running `pip install psycopg-binary` gives an error: `ERROR: Could not find a version that satisfies the requirement psycopg-binary (from versions: none). ERROR: No matching distribution found for psycopg-binary`. So I believe what you said earlier about _This package is not available for every platform_ might be the issue here. – Dula May 06 '22 at 00:54

0 Answers0