## 42.2. Installation and Distutils

Go to http://examples.oreilly.com/upt3 for more information on: python

Installing Python is generally very simple. Either install the appropriate binary package for your platform, or download the latest source from http://www.python.org. (Note that some Linux distributions include Python by default.) A source install is as simple as untarring the distribution, then running:

>     % ./configure
>     % make
>     % make install

You can run the Python interpreter interactively and find out what version you have and details about its compilation. As an example, on my laptop (which runs Windows but also has a Cygwin Unix-like environment installed), Python reports:

>     % python
>     Python 2.2 (#1, Dec 31 2001, 15:21:18)
>     [GCC 2.95.3-5 (cygwin special)] on cygwin
>     Type "help", "copyright", "credits" or "license" for more information.
>     >>>

To see which modules are compiled into your version of Python, examine `sys.builtin_module_names`:

>     >>> import sys
>     >>> print sys.builtin_module_names
>     ('_ _builtin_ _', '_ _main_ _', '_socket', '_sre', '_symtable', 'exceptions',
>      'gc', 'imp', 'marshal', 'new', 'posix', 'signal', 'sys', 'xxsubtype')

These are just the modules that are an integral part of your version of the interpreter. For a complete list of modules installed in your Python, look in all of the directories listed in `sys.path`:

>     >>> print sys.path
>     ['', '/usr/lib/python2.2', '/usr/lib/python2.2/plat-cygwin',
>      '/usr/lib/python2.2/lib-tk', '/usr/lib/python2.2/lib-dynload',
>      '/usr/lib/python2.2/site-packages']

Generally, checking the documentation for the version of Python you have will tell you which modules are normally installed; the site-packages directory is where further packages installed on your machine will likely have been installed.

There is a large repository of modules (and other Python code resources) for Python available at the Vaults of Parnassus (http://www.vex.net/parnassus/), which includes a search mechanism for finding what you're looking for. Most modules will use Distutils to package their distributions.

If you download a module source distribution, you can tell pretty quickly if it was packaged and distributed with Distutils. First, the distribution's name and version number will be featured prominently in the name of the downloaded archive, for example, foo-1.0.tar.gz or widget-0.9.7.zip. Next, the archive will unpack into a similarly-named directory: foo-1.0 or widget-0.9.7. Additionally, the distribution will contain a setup script, setup.py, and a README, which should explain that building and installing the module distribution is a simple matter of running:

>     % python setup.py install

Modules that are not packaged using the standard Distutils will generally include detailed instructions for installing them.

-- DJPH

Copyright © 2003 O'Reilly & Associates. All rights reserved.