Excellent Python Library Distribution Techniques

I wrote Python bindings using ctypes for the unit library. The bindings themselves are only ~ 100 lines of Python. The library does not need (for Python binding purposes) a dependency on tcl, and the configure script fails if tcl is missing. However, the library builds fine with gcc -Wl,-soname,units.so -o units.so -fPIC -shared units.c .

Now I would like to remove these bindings. There are three ways to do this.

  • Release the bindings yourself, with the basic setup.py and providing instructions for building, downloading and installing the C library in the documentation.
  • Release the bindings along with the source library source and provide the setup.py file, which handles compiling and installing the C library. This is obviously more for me.
  • Just release the .py file and let users worry about installation and dependencies.

If I choose option 2, where should I put the library? Should I put it in the same directory as the .py file, which suggests lib_name = CDLL('./units.extension') , or should I put it in a directory that is usually located in the linker path ( e.g. / lib)? Also, how is this usually handled for Windows machines, which a) may not have a C compiler and b) do not have a standard place to host shared libraries?

Which of these options is preferred and what to do with Windows?

+8
python release
source share
1 answer

It seems that the units library has not been changed for more than 5 years, so option 2 may be the best. It is also unlikely that one of the main distributions will pack it (I cannot find it in Ubuntu Lucid or Macports, for example).

For example, copy units.c and units.h into your project and create a setup.py file to compile and deploy it along with your bindings:

 from setuptools import setup, Extension sources = ['src/units.c'] ext_opts = {'extra_compile_args': ['-Wl,-soname,units.so', '-Isrc']} setup( name='units', ext_modules = [Extension('units', sources, **ext_opts)] ) 
+2
source share

All Articles