How do I package for distribution a python module that uses a shared library?

后端 未结 1 1234
太阳男子
太阳男子 2021-02-19 17:53

I\'m writing some bindings for a C library and am not sure how to configure all this for distribution so it is possible to pip install my package.

Let\'s sa

相关标签:
1条回答
  • 2021-02-19 18:12

    The Extensions capability of setuptools/distutils is what you need.

    Documentation has more information, in short an example setup.py to do the above would look like the below

    from setuptools import setup, find_packages, Extension
    
    extensions = [Extension("my_package.ext_library",
                           ["src/library.c"],
                           depends=["src/library.h"],
                           include_dirs=["src"],
                  ),
    ]
    setup(<..>,
         ext_modules=extensions,
    )
    

    The .so is generated automatically by setup.py when the module is built. If it needs to link to other libraries can supply a libraries argument list to the extension. See docs(1) for more info.

    Since this is built in functionality of setuptools, it works fine with pip and can be distributed (as source code only) on pypi. All source files referenced by the Extension must be present in the distributed pypi archive.

    If you want to build distributable binary wheels including native code see manylinux.

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