How to include a shared C library in a Python package

前端 未结 2 1258
野的像风
野的像风 2020-12-25 08:43

I have a project depending on a shared library. To make it clear from the beginning: the shared library is a pure C library and not a Python library. For reasons of simplici

相关标签:
2条回答
  • 2020-12-25 08:51

    package_data is for data. setup can do the compilation into an *.so.

    Following my solution in python setup.py build ctypes.CDLL: cannot open shared object file: No such file or directory, I think your setup could employ ext_modules and py_modules, something like

    setup(name='pkgtest',
          py_modules=['pkgtest'],
          ext_modules=[Extension('src.libhello', ['src/libhello.c'])]
         )
    
    0 讨论(0)
  • 2020-12-25 08:54

    You can create a Python package which includes shared libraries and works on (almost) any linux distro using manylinux.

    The goal of the manylinux project is to provide a convenient way to distribute binary Python extensions as wheels on Linux. This effort has produced PEP 513 which defines the manylinux1_x86_64 and manylinux1_i686 platform tags.

    The general procedure is:

    1. Build the external library and the Python package inside one of the docker containers provided by the manylinux team (see python-manylinux-demo)
    2. Run auditwheel repair to copy the external shared libraries that your package depends on into the Python wheel, setting the RPATH accordingly.

    See .travis.yml and build-wheels.sh in the python-manylinux-demo repo for an example.

    0 讨论(0)
提交回复
热议问题