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?

  • 5
    Python, Makefiles, and build systems belong on Stack Overflow. Two doors down, big statue of Jon Skeet out front. Can't miss it. :) Aug 1, 2010 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. Aug 1, 2010 at 13:23
  • 1
    @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. Aug 1, 2010 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. Aug 2, 2010 at 3:02
  • I would agree except this deals exclusively with packaging for Ubuntu. Aug 3, 2010 at 7:36

4 Answers 4


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)

  • Sorry, I misunderstood what you were saying in your other answer. Oh well. It's probably a good idea to learn distutils anyway. Aug 1, 2010 at 16:38
  • Yes, learn distutils anyway! It won't take you more than a few minutes, I should imagine.
    – Umang
    Aug 2, 2010 at 2:20
  • Well the problem is that distutils expects the files to have a .py extension - which mine does not. Aug 3, 2010 at 7:34
  • 1
    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, 2010 at 6:52

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.

  • 1
    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. Aug 1, 2010 at 16:40

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.

  • 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, 2010 at 2:23

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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