Thursday, February 10, 2011

Getting Started with Distutils

Distutils is such a wonderful tool. It makes installation of Python modules, packages so easy. Here I'm gonna show you how to write a simple file, which is required by distutils.
from distutils.core import setup
import os
import glob

pyfiles = glob.glob("*.py")
pyfiles = [pyfile[:-3] for pyfile in pyfiles]
      packages=['test.test1', 'abc.def'],
Since is basically just a Python script, we can do pretty much anything with it. What this script is trying to do is it will copy all the python files in the root directory as well as the some python packages in the test.test1 and abc.def. The directory structure is like this:
 |--- test/
 |--- mypackage/abc/
As we can see mypackage is not part of package name (there isn't any file there), thus we need package_dir={'abc.def':'mypackage/abc/def'} in the setup() function.

To build a source distribution:
python sdist
To build Linux RPM:
python bdist_prm
To build Windows MSI:
python bdist_msi
To build Windows installer:
python bdist_wininst

To install to the default Python installation:
python install
To install to a particular location:
python install --prefix=/home/whoever/wherever

No comments:

Post a Comment