Distribute a Python package with a compiled dynamic shared library

后端 未结 3 588
灰色年华
灰色年华 2020-12-14 09:08

How do I package a Python module together with a precompiled .so library? Specifically, how do I write setup.py so that when I do this in Python

相关标签:
3条回答
  • 2020-12-14 09:09

    What I ended up doing is:

    setup(
        name='py_my_lib',
        version=version,  # specified elsewhere
        packages=[''],
        package_dir={'': '.'},
        package_data={'': ['py_my_lib.so']},
    )
    

    This way I get to import the lib by its name, and don't have another level of nestedness:

    import py_my_lib
    

    and not

    from py_my_lib_wrapper import py_my_lib
    
    0 讨论(0)
  • 2020-12-14 09:15

    As is mentioned in setupscript.html#installing-package-data:

    setup(
        ...
        package_data={'top_secret_wrapper': ['top_secret.so']},
    )
    
    0 讨论(0)
  • 2020-12-14 09:35

    If that library should also be compiled during install you can describe this as an extension module. If you just want to ship it add it as package_data

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