On Tue, 23 May 2023 at 08:52, Kerrick Staley <ksta...@janestreet.com> wrote: > > If I install psycopg2-binary, and then I try to install a package that > depends on psycopg2, will pip "know" that psycopg2-binary satisfies the > psycopg2 requirement and avoid installing psycopg2? > > Empirically the answer seems to be "no". I installed psycopg2-binary, then > ran `python3 -m pip install -e .` in a directory with this setup.py file, and > it tried to install psycopg2. > > Is there a way that, in my setup.py file, I can depend on either psycopg2 or > psycopg2-binary, whichever is available?
I don't think there is. You cannot make a package depending on either one or the other. Python packaging metadata doesn't offer this flexibility. In psycopg 3 the only package to depend on is `psycopg`. The pre-compiled C module (the `psycopg-binary` package on pypi) can be added as an add-on and it is not necessary for a library to depend on it. It can be an application requirement instead. In my projects I use `psycopg` as an abstract dependency (in the `setup.cfg` of the packages that need psycopg) and `psycopg-binary==3.x.x` as a concrete dependency (in a `requirements.txt` file generated by `pip-tools` using `psycopg-binary in the `requirements.in`) More details about psycopg 3 versions management are available at https://www.psycopg.org/psycopg3/docs/basic/install.html#handling-dependencies -- Daniele