Distributing a Python package with a compiled dynamic shared library

How can I pack a Python module with a precompiled .so library? In particular, how to write setup.py so that when I do this in Python

 >>> import top_secret_wrapper 

Is it easy to find top_secret.so without setting LD_LIBRARY_PATH ?

In my module development environment, I have the following file structure:

 . ├── top_secret_wrapper │  ├── top_secret.so │  └── __init__.py └── setup.py 

Inside __init__.py , I have something like:

 import top_secret 

Here is my setup.py

 from setuptools import setup, Extension setup( name = 'top_secret_wrapper', version = '0.1', description = 'A Python wrapper for a top secret algorithm', url = None, author = 'James Bond', author_email = ' James.Bond.007@mi6.org ', license = 'Spy Game License', zip_safe = True, ) 

I am sure that my setup.py missing a parameter where I specify the location of top_secret.so , although I am not sure how to do this.

+5
source share
2 answers

If this library must also be compiled during installation, you can describe it as an extension module . If you just want to send it, add it as package_data

+1
source

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

 setup( ... package_data={'top_secret_wrapper': ['top_secret.so']}, ) 
0
source

All Articles