0

I developed my first webserver app in Python. It's a but unusual, because it does not only depend on python modules (like tornado) but also on some proprietary C++ libs wrapped using SWIG.

And now it's time to deliver it (to Linux platform).

Due to dependency on C++ lib, just sending sources with requirements.txt does not seem enough. The only workaround would be to have exact Linux installation to ensure binary compatibility of the lib. But in this case there will be problems with LD_PATH etc.

Another option is to write setup.py to create sdist and then deploy it with pip install. Unfortunately that would mean I have to kill all instances of the server before installing my package. The workaround would be to use virtualenv for each instance though.

But maybe I'm missing something much simpler?

1 Answer 1

1

If you need the package to be installed by some user the easiest way will be to write the setup.py - but no just with simple setup function like most of installers. If you look at some packages, they have very complicated setup.py scripts which builds many things and C extensions with installation scripts for many external dependences.

The LD_PATH problem you can solve like this. If your application have an entry-point like some script which you save in python's bin directory (or system /usr/bin) you override LD_PATH like export LD_PATH="/my/path:$LD_PATH".

If your package is system service, like some servers or daemons, you can write system package, for example debian package or rpm. Debian has a lot of scripts and mechanism to point out the dependencies with packages.

So, if you need some system libraries on the list you write it down in package source and debian will install them when you will be installing your package. For example your package have dependencies for SWIG and other DEV modules, and your C extension will be built properly.

3
  • Thanks, I didn't consider system package at all. But how would it handle python package (i.e. my web server) along with SWIG, mongo and other dependencies? Will it be able to install it via pip (after resolving Python dep) ?
    – Kentzo
    Jul 20, 2013 at 7:59
  • Install script in packages are just scripts. You can do what you want.If you hardcode pip install x inside maybe it isn't the prettiest way, but if it works for you, it's ok (if it is not 'pretty public package').Better way (probably) is when you download all PyPI packages and put them inside your system package. Then your system package can: resolve dependencies to mongo, SWIG, and libs, then your install script make a user (for application) then make virtualenv (it's probably cleaner than put all in the system) and install packages you downloaded before(you can keep pip pkgs inside syspkg)
    – spinus
    Jul 20, 2013 at 8:48
  • Check pip bundle command for making one big package with all python dependencies. Additionally, some of the python modules are also packaged as separate system modules (in debian for example there are python-pbs python-gtk and so on). You can make packages for missing python modules (hard way) or you can make a pip bundle and place it inside your system package and use it to install your own python ecosystem for an application (the easy way and you have always versions you want, not the versions from a system).
    – spinus
    Jul 20, 2013 at 8:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.