Re: Does psycopg2-binary provide the psycopg2 package?

From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
To: Kerrick Staley <kstaley(at)janestreet(dot)com>
Cc: psycopg(at)postgresql(dot)org
Subject: Re: Does psycopg2-binary provide the psycopg2 package?
Date: 2023-05-23 11:18:17
Message-ID: CA+mi_8Yxu1845mO5BBTVX3jsYEJqZ8QHWPrSPFDerKoQU2pu1g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

On Tue, 23 May 2023 at 08:52, Kerrick Staley <kstaley(at)janestreet(dot)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

In response to

Browse psycopg by date

  From Date Subject
Next Message Jan-Hendrik Lorenz 2023-06-02 09:10:05 Seeking Insights on Roll-out Process for Multiple PyPI Packages
Previous Message Kerrick Staley 2023-05-22 16:05:43 Does psycopg2-binary provide the psycopg2 package?