Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

In trying to sort out this issue, I have run into the following problem.

I have a Python script that gets installed to /usr/lib/. But I need to get this script into a build system so that I can get it working with my package.

Any help would be appreciated... although I've worked a bit with Makefiles when writing C++ applications before, I've never created any kind of Makefile for Python files. (Nor do I even know where to start.)

How would I go about setting up a build system for my app?

share|improve this question
Python, Makefiles, and build systems belong on Stack Overflow. Two doors down, big statue of Jon Skeet out front. Can't miss it. :) –  Nicholas Knight Aug 1 '10 at 9:38
I disagree. If he's having trouble packaging an app for Ubuntu, I don't see that it's out of place here. –  mac9416 Aug 1 '10 at 13:23
@mac9416: Nothing about his question asks anything remotely specific to Ubuntu, indicates he's having a problem with Ubuntu, indicates a desire to build a native Ubuntu package, or is any way related to Ubuntu. He's non-specifically asking about build systems for Python, very much an SO subject. –  Nicholas Knight Aug 1 '10 at 22:46
I can see your point that there's probably a better place for this question (SO), but I don't think it's completely out of place here. I'll cut George some slack on this one. –  mac9416 Aug 2 '10 at 3:02
I would agree except this deals exclusively with packaging for Ubuntu. –  Nathan Osman Aug 3 '10 at 7:36
show 3 more comments

4 Answers

up vote 6 down vote accepted

Well, like I explained on the other question, you don't need a build system and in that particular case, may be better off without one.

However, the most standard one is distutils. Just provide the metadata (i.e. name, description, etc) and a list of (python) packages, modules and scripts (all of them are optional) and it's done.

Finally, if you'd like to generate a debian package out of your project, then you can very easily do that by using python-stdeb (uses dh7, which I like better) or python-mkdebian (uses cdbs). There are many more differences between these tools, but I'll let you discover them yourself. Just note that both require using distutils. (python-mkdebian is part of the python-distutils-extra package in Ubuntu, I haven't used -extra much, but you can try that as well if you'd like)

share|improve this answer
Sorry, I misunderstood what you were saying in your other answer. Oh well. It's probably a good idea to learn distutils anyway. –  Nathan Osman Aug 1 '10 at 16:38
Yes, learn distutils anyway! It won't take you more than a few minutes, I should imagine. –  Umang Aug 2 '10 at 2:20
Well the problem is that distutils expects the files to have a .py extension - which mine does not. –  Nathan Osman Aug 3 '10 at 7:34
For modules, yes. For packages, an __init__.py file and for scripts no extention. Just list it out as scripts=['foo', 'bar'],. –  Umang Aug 4 '10 at 6:52
add comment

Scons is a build system which uses Python as it's language (I generally prefer it over makefiles for any project), I think it should be capable of what you want to do.

It has a very good User Guide.

share|improve this answer
Oh no! I can't stand scons. I got stuck using a project that used scons. I just ended up writing a Makefile for it. –  Nathan Osman Aug 1 '10 at 16:40
add comment

Umang has the right answer, though perhaps not in as much detail as you might seem to need as a complete beginner.

For a Python program, you need to start by creating a setup.py file. The bulk of the file will be a call to distutils.core.setup - this is discussed in detail in part 2 of the distutils documentation.

All other packaging systems for Python (such as py2exe, setuptools, or Distribute) build on top of the distutils package, usually by extending setup() in some way (with additional parameters or commands).

Before converting this into an Ubuntu package, you can test the setup script by running sudo setup.py install. It should install the files into their expected locations; if it doesn't you may need to check your configuration. In particular, sections 2.5 (scripts) and 2.6 (package data) of the distutils documentation probably apply to your situation.

Once that's done, you can then look at layering on the Ubuntu packaging according to the Ubuntu Packaging Guide for Python. The python-stdeb and python-mkdebian tools suggested by Umang simplify the generation of the various files required for Ubuntu packaging.

share|improve this answer
If you'd like a bit more info, you should know about the distutils deviation from Python upstream. Especially about /usr/local/ instead of /usr/ –  Umang Aug 2 '10 at 2:23
add comment

Make sure to check out:

http://pypi.python.org/pypi/modern-package-template/1.0 For a good default package layout including a starter setup.py file

http://pypi.python.org/pypi/virtualenv For blocking off your dev environment from the rest of your system. Running something like

python setup.py develop

Will build/setup your command into your virtualenv so you can test it out.

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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