Link to or incorporate C dependencies? #3234
Replies: 1 comment 2 replies
In short, you can't via Pex now and likely forevermore. Pex supports Python packaging standards such as they are and that's enough work to keep up with. Supporting native, non-wheeled deps is not planned.
It is not analogous. That said, just use setuptools to package your code and point Pex at your project directory (as a requirement) instead of specifying sources manually. Here Pex dogsfoods that idea packaging itself in a PEX by using pex/scripts/create-packages.py Lines 33 to 127 in 5263d73 |
Uh oh!
There was an error while loading. Please reload this page.
I'm trying to deploy a .pex with code that uses the python-ldap library, which links against the OpenLDAP C library. This library is installed both on my machine (where the .pex is built) and the target machine, but the two machines are running different versions of Ubuntu (24.04 and 22.04 LTS respectively) and the binary that
ldapwants to use has a different name in the two environments. When I try to run it, I get the errorThe binary on the target machine is
libldap.so(without the.2), but on my machine that is the correct binary. My working hypothesis is that python-ldap's internal_ldapmodule is being built against that binary byuv, and then the built module is being packaged into the .pex. This seems to be supported by the fact that my prod environment, which is not yet using PEX, seems to be linking againstlibldap.so.This is not the first time I've run into issues building and deploying python-ldap specifically and I'm about to rewrite with
ldap3over it, but I have other C-linked libraries without pure-Python alternatives likepsycopg, as well, and I worry it's only a matter of time before one of them doesn't provide prebuilt binaries and causes a similar problem. The docs and-hoption aren't making it obvious if/how I can roll C binaries into the .pex or at least override the location(s) that modules should look for them.I thought
--sciemight be the answer, but it seems that just includes the CPython interpreter. I also see-D, but the description only suggests it includes files in the .pex but is silent on whether those files would be extracted somewhere as with setuptools'data-filesoption. (If it is completely analogous todata-files, then this is probably the answer I'm looking for!)While I'm open to workarounds for OpenLDAP/python-ldap specifically, my actual question is:
In general, how can I ensure that C libraries linked to by Python modules can be either included in the .pex archive itself or made discoverable to such modules, or delay building of the Python C module to after the .pex is deployed so it can link to that environment?
All reactions