In practice, there are two distribution options for such a package: bdist_wheel and sdist .
Take the SWIG example from docs for distutils .
example.h
int fact(int n);
example.c
#include "example.h" int fact(int n) { if (n == 0) { return 1; } else { return n * fact(n - 1); } }
example.i
%module example %{ #define SWIG_FILE_WITH_INIT #include "example.h" %} int fact(int n);
Let him build the SWIG interface, which by default creates example_wrap.c .
swig -python example.i
Wheel
Python Wheels is a modern distribution format that simplifies the distribution of ready-made packages (i.e. package users do not need a compiler, development headers, etc.). To use it, we need setuptools and wheel (can be installed using pip or from the OS repositories, sudo apt-get install python-wheel python-setuptools ).
setup.py
from setuptools import setup, Extension setup( name = 'example', version = '0.1', author = 'SWIG Docs', description = 'Simple swig example from docs', ext_modules = [ Extension('_example', sources = ['example_wrap.c', 'example.c'])], py_modules = ['example'], package_data = {'': ['example.h']} # needed for sdist )
You can create a wheel with:
python setup.py bdist_wheel
On my machine, it creates example-0.1-cp27-cp27mu-linux_x86_64.whl , which I can install with pip and check as python -c 'import example; print(example.fact(5))' python -c 'import example; print(example.fact(5))' . Pay attention to the file name. It encodes a compatible version of Python, ABI, and platform. Here's a listing of the contents ( unzip -l ... ).
Archive: example-0.1-cp27-cp27mu-linux_x86_64.whl Length Date Time Name --------- ---------- ----- ---- 2609 2018-02-24 11:06 example.py 70968 2018-02-24 13:31 _example.so 10 2018-02-24 14:58 example-0.1.dist-info/DESCRIPTION.rst 290 2018-02-24 14:58 example-0.1.dist-info/metadata.json 17 2018-02-24 14:58 example-0.1.dist-info/top_level.txt 105 2018-02-24 14:58 example-0.1.dist-info/WHEEL 193 2018-02-24 14:58 example-0.1.dist-info/METADATA 617 2018-02-24 14:58 example-0.1.dist-info/RECORD --------- ------- 74809 8 files
To create wheels with better compatibility, you can, for example, look at manylinux .
A source
sdist means source distribution, which means your users will need to have a compiler and corresponding development dependencies. Source distribution is built using:
python setup.py sdist
The example-0.1.tar.gz contains ( tar -tf ... ):
example-0.1/ example-0.1/example.c example-0.1/PKG-INFO example-0.1/example.egg-info/ example-0.1/example.egg-info/PKG-INFO example-0.1/example.egg-info/dependency_links.txt example-0.1/example.egg-info/top_level.txt example-0.1/example.egg-info/SOURCES.txt example-0.1/setup.cfg example-0.1/example.py example-0.1/setup.py example-0.1/example_wrap.c example-0.1/example.h