Should I link C libraries to my Python application?

If I have a Python package that depends on some C libraries (e.g. Gnu Scientific Library (GSL) for numerical computing, for example), is it nice to link the library to my code?

I would like to make my package as simple as possible for users to install, and I do not want them to download the C libraries manually and supply include-paths. Also, I could always make sure that the version of the library I'm sending is compatible with my code.

However, is it possible that there are conflicts if the user has already installed the library or if there are any other reasons why I should not do this?

I know that I can make it easier for users by simply providing a binary distribution, but I would like to avoid having to support binary distributions for all possible OSs. So I would like to stick with the original distribution, but for the user (who proudly owns the C compiler) the installation should be as simple as python setup.py install .

+7
source share
3 answers

Distribution is one of the difficult parts for any software project. Java and .NET take up some of this burden by defining standard runtimes and then simply saying β€œjust spread the rest.” Of course, there is a drawback: everything must be rewritten in a language supported by the runtime β€” as soon as you want to use your own code, you will lose all the benefits.

This is harder in Python, as in Ruby, C, C ++ and other languages, since they usually use existing native libraries.

Generally speaking:

  • As an example, you can get the original sdist using pypi.python.org. Set your install_requires correctly (you may need python bindings for GSL, not GSL). Use standard setuptools / layout distribution. This will allow anyone, let them say, to support the package for any distribution, to pick up your software and pack it.

  • Also, consider providing a full-blown installable package for your audience. You do not need to support all distributions and the operating system; Choose one or two that you consider most used. Tools like PyInstaller will allow you to create an installable, executable package for many operating systems, but especially for Linux it may require the user to install a distribution kit of their own version of transitive fingerprints (libgsl?) - you will need a full-blown deb or rpm package to satisfy this - again do not try to support any distribution, you will be insane. Maintain what you use most and let other users help you with other packaging needs.

Also take a look at the Python Packaging Guide

+4
source

You can have two separate src branches, one of which contains libraries, and the other not. This way you can explicitly warn your users if they have installed libraries. Another solution might be (if the licenses allow you libraries) is to wrap them in a single file.

I think that there is no single solution, but these are the ideas that I could think of.

Good luck.

0
source

You can use virtualenv to create a private Python environment for your application. This avoids conflicts with other libraries. It is best to pack modules and dependencies, such as your libraries, using Distribute . Distutils is something worth exploring.

0
source

All Articles