How to include external library with python wheel package

前端 未结 2 1639
攒了一身酷
攒了一身酷 2020-12-07 22:56

I want to create package for python that embeds and uses an external library (.so) on Linux using the cffi module.

Is there standard way to include .so

2条回答
  •  执念已碎
    2020-12-07 23:50

    Wheels are the standard way of distributing Python packages, but there is a problem when you have extension modules that depend on other so's. This is because the normal Linux dynamic linker is used, and that only looks in /usr/lib or /usr/local/lib. This is a problem when installing a wheel in a virtualenv.

    As far as I know, you have three options:

    • Static linking, so the 'wrapper' does not depend on anything else;
    • using ctypes to wrap the so directly from Python;
    • Split the distribution into a wheel with the Python code & wrapper, and a separate RPM or DEB to install the so into either /usr/lib or /usr/local/lib.

    A wheel may work if you include the dependent so as a data file to be stored in /lib and install into the root Python environment (haven't tried that), but this will break if someone tries to install the wheel into a virtualenv (did try that).

提交回复
热议问题