0

I have a py2exe built program which is failing because it needs a copy of zlib.pyd. How do I build this? I can create zlib.dll (or .lib) from source, I can compile Python from source, I've worked with distutils, py2exe, and pyinstaller a pretty decent amount, so I have a good feel for the "landscape" - but I'm not sure how to go about directly generating a .pyd like this.

Update:

I found this:

building Python from source with zlib support

Which seems to be the answer for Linux, but this is not quite applicable in Windows using nmake...

BuvinJ
  • 10,221
  • 5
  • 83
  • 96
  • Are you running py2exe against a standard install of Python? If so, you almost certainly just want to get py2exe to copy the existing `zlib.pyd` out of the stdlib, not build a new copy of it. – abarnert Aug 07 '18 at 01:11
  • if you really _do_ need to build a copy of it, assuming you want to build the one out of the CPython source tree, IIRC it's a matter of editing `Modules/Setup.local`, copying in the `zlib` section from `Modules/Setup`, uncommenting it, and then you can… I don't know the last step on Windows (on *nix, it's a `make` command…). – abarnert Aug 07 '18 at 01:13
  • Thanks @abarnert. I'll check that out. There is no zlib.pyd by the way packaged with a standard install of Python. Nor does CPython naturally build one. Hence the question! I did find an old random copy floating around the web, but when I tried that it failed because it wanted to talk an old version of the base python.dll. So, you are right that there needs to be version matching. – BuvinJ Aug 07 '18 at 12:21
  • On Windows, it seems the file is Setup.dist. Else, that's a Python version discrepancy. I'm working with v.2.7. There is already a zlibmodule line there in a comment. I uncommented it, ran the build, everything succeeded, but there is no .pyd to be found! I'm trying to use distutil now, to build an extension from the zlibmodule.c file directly. I almost have that working, but am running into linker errors... – BuvinJ Aug 07 '18 at 13:56
  • `zlib` has been part of the Python stdlib since 1.5 or so. If there's no `zlib.pyd`, it must be linked into the interpreter (in `python27.dll`), in which case you shouldn't need it in your py2exe app. Can you `import zlib` from within Python? If so, I think you're trying to solve the wrong problem here. – abarnert Aug 07 '18 at 15:44
  • I've come to think you're right that zlib is simply rolled into the interpreter. Yet, when I package this dll I'm working on, it fails and using Dependency Walker reveals the cause is a LoadLibraryA failure with zlib.pyd. Without that file present, it claims that dependency is missing. I managed to build one now, in a round about ugly manner, but it is still failing, despite being found... – BuvinJ Aug 07 '18 at 19:03
  • As a test, I just built a tiny exe (rather than a dll) using py2exe, which simply runs a zlib test. That exe works, and there is no zlib.pyd required. I'm going to try something similar with a dll now. Unfortunately, in my actual use case I have a substantial library being imported that comes from Google. I have no idea where and how they use zlib. – BuvinJ Aug 07 '18 at 19:20
  • Ugh... Yeah I have a dll (com server) example now using zlib directly and it works without any issue. It definitely seems Dependency Walker threw a red herring my way! – BuvinJ Aug 07 '18 at 19:29

0 Answers0