Обсуждение: How to build psycopg2 for Windows
Can anyone give me a solution to build psycopg2 statically on Windows?
I have succeeded in building it, but when I run dumpbin /dependents on the generated file (the PYD file), it still depends on libpq.dll even when I pass --static-libpq.
Environment
- OS: Windows 10
- Psycopg version: psycopg2-2.8.5
- Python version: 3.9
- PostgreSQL version: 14.0 (from ZIP)
- pip version: 21.2.4
- Visual C++ version: 2019
- Psycopg version: psycopg2-2.8.5
- Python version: 3.9
- PostgreSQL version: 14.0 (from ZIP)
- pip version: 21.2.4
- Visual C++ version: 2019
Procedure
- Make sure pg_config and psql are in the path
- Download as follows - pip download psycopg2==2.8.5 --no-binary :all:
- Expand the tarball
- Build in that directory as follows:
python setup.py build_ext --static-libpq
- Try to verify it is indeed static
dumpbin /dependents build\lib.win-amd64-3.9\psycopg2\_psycopg.cp39-win_amd64.pyd
Background
The purpose here is 2 fold:
* Backfill support for Python 3.9 and psycopg2 to versions that may have come out before 3.9 was available.
* Make sure our psycopg2 is built against a more recent version of the PostgreSQL client libraries than 9.x
On Tue, 5 Oct 2021 at 00:30, Dan Davis <dansmood@gmail.com> wrote: > > Can anyone give me a solution to build psycopg2 statically on Windows? You can follow what Appveyor does, which is the CI that builds psycopg2 packages. - this is the setup https://github.com/psycopg/psycopg2/blob/master/.appveyor/packages.yml - this is the script it calls into: https://github.com/psycopg/psycopg2/blob/master/scripts/build/appveyor.py You can use the ML at psycopg@postgres.org for further questions. -- Daniele
Daniele (namesake),
Thanks for the quick response. I tried that, it looks like https://github.com/psycopg/psycopg2/blob/master/scripts/build/appveyor.py#L291 shows the build step:
python setup.py build_ext -l "libpgcommon libpgport"
After that, I still get a binary that depends on libpq.dll - but when I install psycopg2-binary, the DLL installed (the PYD file) does not depend on libpq.dll - it is statically built.
On Mon, Oct 4, 2021 at 6:41 PM Daniele Varrazzo <daniele.varrazzo@gmail.com> wrote:
On Tue, 5 Oct 2021 at 00:30, Dan Davis <dansmood@gmail.com> wrote:
>
> Can anyone give me a solution to build psycopg2 statically on Windows?
You can follow what Appveyor does, which is the CI that builds
psycopg2 packages.
- this is the setup
https://github.com/psycopg/psycopg2/blob/master/.appveyor/packages.yml
- this is the script it calls into:
https://github.com/psycopg/psycopg2/blob/master/scripts/build/appveyor.py
You can use the ML at psycopg@postgres.org for further questions.
-- Daniele