Installing Python Modules, Release 3.3.3
2.3 How building works
As implied above, the build command is responsible for putting the files to install into a build directory. By
default, this is build under the distribution root; if you’re excessively concerned with speed, or want to keep the
source tree pristine, you can change the build directory with the --build-base option. For example:
python setup.py build --build-base=/path/to/pybuild/foo-1.0
(Or you could do this permanently with a directive in your system or personal Distutils configuration file; see
section Distutils Configuration Files.) Normally, this isn’t necessary.
The default layout for the build tree is as follows:
--- build/ --- lib/
or
--- build/ --- lib.<plat>/
temp.<plat>/
where <plat> expands to a brief description of the current OS/hardware platform and Python version. The first
form, with just a lib directory, is used for “pure module distributions”—that is, module distributions that include
only pure Python modules. If a module distribution contains any extensions (modules written in C/C++), then the
second form, with two <plat> directories, is used. In that case, the temp.plat directory holds temporary files
generated by the compile/link process that don’t actually get installed. In either case, the lib (or lib.plat)
directory contains all Python modules (pure Python and extensions) that will be installed.
In the future, more directories will be added to handle Python scripts, documentation, binary executables, and
whatever else is needed to handle the job of installing Python modules and applications.
2.4 How installation works
After the build command runs (whether you run it explicitly, or the install command does it for you), the
work of the install command is relatively simple: all it has to do is copy everything under build/lib (or
build/lib.plat) to your chosen installation directory.
If you don’t choose an installation directory—i.e., if you just run setup.py install—then the install com-
mand installs to the standard location for third-party Python modules. This location varies by platform and by how
you built/installed Python itself. On Unix (and Mac OS X, which is also Unix-based), it also depends on whether
the module distribution being installed is pure Python or contains extensions (“non-pure”):
Platform Standard installation location Default value Notes
Unix (pure) prefix/lib/pythonX.Y/site-packages /usr/local/lib/pythonX.Y/site-packages (1)
Unix (non-pure) exec-prefix/lib/pythonX.Y/site-packages /usr/local/lib/pythonX.Y/site-packages (1)
Windows prefix\Lib\site-packages C:\PythonXY\Lib\site-packages (2)
Notes:
1. Most Linux distributions include Python as a standard part of the system, so prefix and exec-prefix
are usually both /usr on Linux. If you build Python yourself on Linux (or any Unix-like system), the
default prefix and exec-prefix are /usr/local.
2. The default installation directory on Windows was C:\Program Files\Python under Python 1.6a1,
1.5.2, and earlier.
prefix and exec-prefix stand for the directories that Python is installed to, and where it finds its libraries at
run-time. They are always the same under Windows, and very often the same under Unix and Mac OS X. You can
find out what your Python installation uses for prefix and exec-prefix by running Python in interactive
mode and typing a few simple commands. Under Unix, just type python at the shell prompt. Under Windows,
choose Start → Programs → Python X.Y → Python (command line). Once the interpreter is started, you type
Python code at the prompt. For example, on my Linux system, I type the three Python statements shown below,
and get the output as shown, to find out my prefix and exec-prefix:
6 Chapter 2. Standard Build and Install