How-To's‎ > ‎Python‎ > ‎

Building Packages


This page is somewhat a tutorial. We will describe how to package the little project vizmdend
It is a good idea to create a repository. We used Github, which offers an amazing service for the price tag (it's free!)
Supporting tutorials on building packages are those of the Python package Index.

Package Structure

The package should follow a standard ordering when placing the files.

    vizmdend/
    |
    + - - REAMDE.txt
    + - - LICENSE.txt
    + - - CHANGES.txt
    + - - setup.py
    + - - vizmdend/
            |
            + - - __init__.py
            + - - file1.py
            + - - file2.py

The setup.py script


The critical part is the setup.py script, which contains a call to the distutils.core.setup method.

One of the arguments passed to the distutils.core.setup method is the packages arguments, which in this case take the value packages = ['vizmdend',]. This indicates that vizmdend is not a single python module but a subdirectory containing many modules.

You must define the scope of your package by selecting one (or more) of the approved topic classifiers. Only the classifiers in the previous list are allowed !

The MANIFEST.in file

By default, distutils will include the following files in your release package:

  • README.txt
  • setup.py
  • The .py files needed by the multi-file modules listed in the packages parameter
  • The individual .py files listed in the py_modules parameter
However, package vizmdend contains files required for the graphical interface that should be included. File MANIFEST.in instruct distutils to do just that. These files are located under the source subdirectory vizmdend/.

Checking the setup.py

In the command prompt: python setup.py check

Creating the Package

A source distributionpython setup.py sdist will create file MANIFEST containing the packaged files, as well as subdirectory dist/ containing the tarred package.

A windows graphical installer (NOTE: you will require a fairly recent build for python 2.7.3 in your system): python setup.py bdist_wininst will create the MANIFEST file as well as a windows executable *.exe within dist/ subdirectory. This executable is the installer.

Uploading to PYPI

If not already registered at PYPI, do so.

Register and upload your package: python setup.py register sdist bdist_wininst upload. When you release your project for the first time, Distutils will add your software to the Python Package Index and give it its own URL. Every time after that, it will simply update the project metadata with any changes you may have made in your setup.py parameters. Next, it builds a source distribution (sdist) and a Windows installer (bdist_wininst) then uploads them to PyPI (upload).

The address is http://pypi.python.org/pypi/NAME , where NAME is the string you passed in the name parameter in your setup.py file.