Standalone Python Applications on Linux

How can I distribute a standalone Python application on Linux?

I think I can take for granted the presence of the recent Python interpreter in any modern distribution. The problem is related to those libraries that do not belong to the standard library, i.e. wxPython, scipy, the cryptographic toolset python, reportlab, etc.

Is there a working analogue of Linux, say, py2exe (which, by the way, I have never tried)? Is there any free, open source?

+28
python linux
Oct. 10 '08 at 21:26
source share
8 answers

Create deb (for everything derived from Debian) and rpm (for Fedora / SuSE). Add the correct dependencies to the package, and you can be sure that it will work.

+22
Oct 11 '08 at 11:05
source share

You can use cx_Freeze for this. This is similar to py2exe (integrates the interpreter and the launch of the script and all the necessary libraries and modules), but it works on both Linux and Windows.

It collects dependencies from the environment in which it runs, which means that they must also be suitable for the recipient. If you are doing something like building 32-bit Debian and deploying to another 32-bit Debian, then this is fine. You can handle 32/64 bit difference by creating several versions in the respective environments (for example, 32-bit and 64-bit chroots) and distributing the corresponding ones. If you need something more general (like on Debian, deployment on any distribution), then this gets a little bleak depending on what your dependencies are.

If you make a fairly simple distribution (i.e. you know that the build environment and the deployment environment are similar), this avoids the rather complicated step of rpm / deb / egg / etc (using cx_Freeze is very simple, especially if you are familiar with py2exe). If not, then everything from rolling your dependency installer to deb / rpm / egg / etc will work, depending on how much work you want to do, how much flexibility with the required versions you want to offer and what the dependencies are.

+10
May 26 '09 at 5:32 a.m.
source share

You can see dependency declarations in setuptools . This can provide a way to ensure that the correct packages are either available in the environment or can be installed by someone with the appropriate rights.

+9
Oct 10 '08 at 21:44
source share

You cannot easily do this in a neutral format. The only reliable dependency tracking mechanisms are built into package management systems in distributions and will vary from distribution to distribution. You really need to do rpm for fedora, debs for ubuntu and debian, etc.

Py2exe works fine on Windows. It creates a distribution with all the necessary DLL and shell for the python interpreter, which runs your program. It's quite simple to install - just drop it into a directory, so creating an MSI file is trivial for it.

+7
Oct 10 '08 at 21:34
source share

Setuptools is too much for me, since my use of the program is quite limited, so here is my home alternative.

I will link a "third-party" directory that includes all the prerequisites and uses site.addsitedir, so they do not need to be installed globally.

# program startup code import os import sys import site path = os.path.abspath(os.path.dirname(__file__)) ver = 'python%d.%d' % sys.version_info[:2] thirdparty = os.path.join(path, 'third-party', 'lib', ver, 'site-packages') site.addsitedir(thirdparty) 

Most of my presets have setup.py installers. Each plug-in gets its own "installation" process, so any custom materials (such as. / Configure) can start automatically. My installation script runs this makefile as part of the installation process.

 # sample third-party/Makefile PYTHON_VER = `python -c "import sys; \ print 'python%d.%d' % sys.version_info[:2]"` PYTHON_PATH = lib/$(PYTHON_VER)/site-packages MODS = egenix-mx-base-3.0.0 # etc .PHONY: all init clean realclean $(MODS) all: $(MODS) $(MODS): init init: mkdir -p bin mkdir -p $(PYTHON_PATH) clean: rm -rf $(MODS) realclean: clean rm -rf bin rm -rf lib egenix-mx-base-3.0.0: tar xzf $@.tar.gz cd $@ && python setup.py install --prefix=.. rm -rf $@ 
+5
12 Oct. '08 at 17:48
source share

The standard python way is to create the Egg python.

You can see this tutorial or this page about setuptools .

+3
Oct 13 '08 at 19:56
source share

I think that you can quite safely use the provided python support for most modern Linux distributions - for those who do not, as long as an error message is given, users will probably be able to work on how to get them on their own (you can use simple bash running script for this):

 #!/bin/bash if [ -e /usr/bin/python ] then echo "Python found!" else echo "Python missing!" fi 
0
Jan 06 '10 at 13:00
source share

Nope.

Python is known to be flaky regarding various settings. The only sensible way to deploy a python application is to send the whole set of interpreter and libraries you rely on with your code. This is likely to work.

-10
Oct. 10 '08 at 21:28
source share



All Articles