A comprehensive guide through Python packaging (a.k.a. setup scripts)
One of the really useful things in python are the setup scripts. When doing “serious” business, you really should look into them. Setup scripts are amazingly powerful. But they don’t necessarily need to be complex. But because of this flexibility, the documentation around them seems like a lot to read. Additionally, the state of packaging has changed quite a bit over the years. So you now have a couple of packages (distutils, setuptools, distribute) which all seem to try to solve the same problem. See the current state of packaging for more details on this.
This post attempts to summarize the important bits using a “Hello World” project and steeping through the process of creating the setup.py file:
- Creating a package distribution
- Automatic generation of executables
- Version numbers
- Dependency management
- Publishing your package (thus also making it available for automatic dependency resolution)
- Some more food for thought.
- importing the package itself (to centralize the version number)
- Reading the long_description content from a text-file
Both methodologies have their issues. Importing the package only works if you can import it cleanly (i.e. without dependencies) from standard python. Reading the text file only works if the setup.py is called from the proper location.
This is mostly true. There are corner-cases however where this is not possible. If that is the case, you will need to live without these helpful shortcuts. See the comments on this article for more on this.
Posted in Python | 18 Comments »

