blob: fab4d2a28a8ad7b377682996e6708fed798410d7 [file] [log] [blame]
Greg Ward7c1e5f62000-03-10 01:56:58 +00001\documentclass{howto}
2\usepackage{ltxmarkup}
3\usepackage{times}
Greg Ward7593eb32000-04-09 03:59:15 +00004\usepackage{distutils}
Greg Ward7c1e5f62000-03-10 01:56:58 +00005
6\title{Installing Python Modules}
7
8% The audience for this document includes people who don't know anything
9% about Python and aren't about to learn the language just in order to
10% install and maintain it for their users, i.e. system administrators.
11% Thus, I have to be sure to explain the basics at some point:
12% sys.path and PYTHONPATH at least. Should probably give pointers to
13% other docs on "import site", PYTHONSTARTUP, PYTHONHOME, etc.
14%
15% Also, I need to take into account that most modules out there don't
16% (yet) use Distutils: briefly explain the old Makefile.pre.in
17% convention (maybe move material from the E&E manual to here?), and
18% explain where to copy .py and .so files manually if the distribution
19% doesn't provide a mechanism for doing so.
20%
21% Finally, it might be useful to include all the material from my "Care
22% and Feeding of a Python Installation" talk in here somewhere. Yow!
23
Greg Ward7c1e5f62000-03-10 01:56:58 +000024\author{Greg Ward}
25\authoraddress{E-mail: \email{gward@python.net}}
26
Greg Warde3cca262000-08-31 16:36:31 +000027\makeindex
Greg Ward7c1e5f62000-03-10 01:56:58 +000028
29\begin{document}
30
31\maketitle
32
Greg Warde3cca262000-08-31 16:36:31 +000033\begin{abstract}
34 \noindent
35 This document describes the Python Distribution Utilities
36 (``Distutils'') from the end-user's point-of-view, describing how to
37 extend the capabilities of a standard Python installation by building
38 and installing third-party Python modules and extensions.
39\end{abstract}
40
Greg Ward7c1e5f62000-03-10 01:56:58 +000041%\begin{abstract}
42%\noindent
43%Abstract this!
44%\end{abstract}
45
46\tableofcontents
47
48\section{Introduction}
Greg Warde78298a2000-04-28 17:12:24 +000049\label{intro}
Greg Ward7c1e5f62000-03-10 01:56:58 +000050
Greg Ward6002ffc2000-04-09 20:54:50 +000051Although Python's extensive standard library covers many programming
52needs, there often comes a time when you need to add some new
53functionality to your Python installation in the form of third-party
54modules. This might be necessary to support your own programming, or to
55support an application that you want to use and that happens to be
56written in Python.
57
58In the past, there has been little support for adding third-party
59modules to an existing Python installation. With the introduction of
Fred Drake01df4532000-06-30 03:36:41 +000060the Python Distribution Utilities (Distutils for short) in Python 2.0,
Greg Ward6002ffc2000-04-09 20:54:50 +000061this is starting to change. Not everything will change overnight,
62though, so while this document concentrates on installing module
63distributions that use the Distutils, we will also spend some time
64dealing with the old ways.
65
66This document is aimed primarily at the people who need to install
67third-party Python modules: end-users and system administrators who just
68need to get some Python application running, and existing Python
69programmers who want to add some new goodies to their toolbox. You
70don't need to know Python to read this document; there will be some
71brief forays into using Python's interactive mode to explore your
72installation, but that's it. If you're looking for information on how
73to distribute your own Python modules so that others may use them, see
Fred Drake01df4532000-06-30 03:36:41 +000074the \citetitle[../dist/dist.html]{Distributing Python Modules} manual.
Greg Ward7c1e5f62000-03-10 01:56:58 +000075
76
Greg Ward6002ffc2000-04-09 20:54:50 +000077\subsection{Best case: trivial installation}
Greg Ward1ed49ee2000-09-13 00:00:58 +000078\label{trivial-install}
Greg Ward6002ffc2000-04-09 20:54:50 +000079
80In the best case, someone will have prepared a special version of the
81module distribution you want to install that is targeted specifically at
82your platform and is installed just like any other software on your
83platform. For example, the module developer might make an executable
84installer available for Windows users, an RPM package for users of
85RPM-based Linux systems (Red Hat, SuSE, Mandrake, and many others), a
86Debian package for users of Debian-based Linux systems (Debian proper,
87Caldera, Corel, etc.), and so forth.
88
89In that case, you would download the installer appropriate to your
Greg Wardc392caa2000-04-11 02:00:26 +000090platform and do the obvious thing with it: run it if it's an executable
91installer, \code{rpm --install} it if it's an RPM, etc. You don't need
92to run Python or a setup script, you don't need to compile
93anything---you might not even need to read any instructions (although
94it's always a good idea to do so anyways).
Greg Ward6002ffc2000-04-09 20:54:50 +000095
96Of course, things will not always be that easy. You might be interested
Greg Wardc392caa2000-04-11 02:00:26 +000097in a module distribution that doesn't have an easy-to-use installer for
98your platform. In that case, you'll have to start with the source
99distribution released by the module's author/maintainer. Installing
100from a source distribution is not too hard, as long as the modules are
101packaged in the standard way. The bulk of this document is about
102building and installing modules from standard source distributions.
Greg Ward7c1e5f62000-03-10 01:56:58 +0000103
104
Greg Ward6002ffc2000-04-09 20:54:50 +0000105\subsection{The new standard: Distutils}
Greg Warde78298a2000-04-28 17:12:24 +0000106\label{new-standard}
Greg Ward6002ffc2000-04-09 20:54:50 +0000107
108If you download a module source distribution, you can tell pretty
Greg Ward19c67f82000-06-24 01:33:16 +0000109quickly if it was packaged and distributed in the standard way, i.e.
110using the Distutils. First, the distribution's name and version number
111will be featured prominently in the name of the downloaded archive, e.g.
Greg Ward6002ffc2000-04-09 20:54:50 +0000112\file{foo-1.0.tar.gz} or \file{widget-0.9.7.zip}. Next, the archive
113will unpack into a similarly-named directory: \file{foo-1.0} or
114\file{widget-0.9.7}. Additionally, the distribution will contain a
115setup script \file{setup.py}, and a \file{README.txt} (or possibly
116\file{README}), which should explain that building and installing the
117module distribution is a simple matter of running
118\begin{verbatim}
119python setup.py install
120\end{verbatim}
121
122If all these things are true, then you already know how to build and
123install the modules you've just downloaded: run the command above.
124Unless you need to install things in a non-standard way or customize the
125build process, you don't really need this manual. Or rather, the above
126command is everything you need to get out of this manual.
Greg Ward7c1e5f62000-03-10 01:56:58 +0000127
128
Greg Ward6002ffc2000-04-09 20:54:50 +0000129\subsection{The old way: no standards}
Greg Warde78298a2000-04-28 17:12:24 +0000130\label{old-way}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000131
Greg Ward6002ffc2000-04-09 20:54:50 +0000132Before the Distutils, there was no infrastructure to support installing
133third-party modules in a consistent, standardized way. Thus, it's not
134really possible to write a general manual for installing Python modules
135that don't use the Distutils; the only truly general statement that can
Greg Wardc392caa2000-04-11 02:00:26 +0000136be made is, ``Read the module's own installation instructions.''
Greg Ward6002ffc2000-04-09 20:54:50 +0000137
Greg Ward19c67f82000-06-24 01:33:16 +0000138However, if such instructions exist at all, they are often woefully
Greg Wardc392caa2000-04-11 02:00:26 +0000139inadequate and targeted at experienced Python developers. Such users
140are already familiar with how the Python library is laid out on their
141platform, and know where to copy various files in order for Python to
142find them. This document makes no such assumptions, and explains how
143the Python library is laid out on three major platforms (Unix, Windows,
144and Mac~OS), so that you can understand what happens when the Distutils
145do their job \emph{and} know how to install modules manually when the
146module author fails to provide a setup script.
Greg Ward6002ffc2000-04-09 20:54:50 +0000147
148Additionally, while there has not previously been a standard
149installation mechanism, Python has had some standard machinery for
150building extensions on Unix since Python \XXX{version?}. This machinery
151(the \file{Makefile.pre.in} file) is superseded by the Distutils, but it
152will no doubt live on in older module distributions for a while. This
153\file{Makefile.pre.in} mechanism is documented in the ``Extending \&
154Embedding Python'' manual, but that manual is aimed at module
155developers---hence, we include documentation for builders/installers
156here.
157
158All of the pre-Distutils material is tucked away in
Greg Warde78298a2000-04-28 17:12:24 +0000159section~\ref{pre-distutils}.
Greg Ward7c1e5f62000-03-10 01:56:58 +0000160
161
Greg Ward29576562000-03-18 15:11:50 +0000162\section{Standard Build and Install}
Greg Ward1ed49ee2000-09-13 00:00:58 +0000163\label{standard-install}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000164
Greg Warde78298a2000-04-28 17:12:24 +0000165As described in section~\ref{new-standard}, building and installing
Greg Ward6002ffc2000-04-09 20:54:50 +0000166a module distribution using the Distutils is usually one simple command:
167\begin{verbatim}
168python setup.py install
169\end{verbatim}
170On Unix, you'd run this command from a shell prompt; on Windows, you
Greg Warde24f05e2000-09-12 23:55:19 +0000171have to open a command prompt window (``DOS box'') and do it there; on
172Mac~OS, things are a tad more complicated (see below).
Greg Ward6002ffc2000-04-09 20:54:50 +0000173
174
175\subsection{Platform variations}
Greg Ward1ed49ee2000-09-13 00:00:58 +0000176\label{platform-variations}
Greg Ward6002ffc2000-04-09 20:54:50 +0000177
178You should always run the setup command from the distribution root
179directory, i.e. the top-level subdirectory that the module source
180distribution unpacks into. For example, if you've just downloaded a
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000181module source distribution \file{foo-1.0.tar.gz} onto a Unix system, the
Greg Ward6002ffc2000-04-09 20:54:50 +0000182normal thing to do is:
183\begin{verbatim}
184gunzip -c foo-1.0.tar.gz | tar xf - # unpacks into directory foo-1.0
185cd foo-1.0
186python setup.py install
187\end{verbatim}
188
Greg Warde24f05e2000-09-12 23:55:19 +0000189On Windows, you'd probably download \file{foo-1.0.zip}. If you
190downloaded the archive file to \file{C:\textbackslash{}Temp}, then it
191would unpack into \file{C:\textbackslash{}Temp\textbackslash{}foo-1.0};
192you can use either a GUI archive manipulator (such as WinZip) or a
193command-line tool (such as \program{unzip} or \program{pkunzip}) to
194unpack the archive. Then, open a command prompt window (``DOS box''),
195and run:
Greg Ward6002ffc2000-04-09 20:54:50 +0000196\begin{verbatim}
Greg Warde24f05e2000-09-12 23:55:19 +0000197cd c:\Temp\foo-1.0
Greg Ward6002ffc2000-04-09 20:54:50 +0000198python setup.py install
199\end{verbatim}
200
Greg Warde24f05e2000-09-12 23:55:19 +0000201On Mac~OS, you have to go through a bit more effort to supply
202command-line arguments to the setup script:
203\begin{itemize}
204\item hit option-double-click on the script's icon (or option-drop it
205 onto the Python interpreter's icon)
206\item press the ``Set unix-style command line'' button
207\item set the ``Keep stdio window open on termination'' if you're
208 interested in seeing the output of the setup script (which is usually
209 voluminous and often useful)
Greg Ward15f5e2a2000-09-26 02:54:43 +0000210\item when the command-line dialog pops up, enter ``install'' (you
Greg Warde24f05e2000-09-12 23:55:19 +0000211 can, of course, enter any Distutils command-line as described in this
212 document or in the ``Distributing Python Modules'' document: just
213 leave of the initial \code{python setup.py} and you'll be fine)
214\end{itemize}
215\XXX{this should change: every Distutils setup script will need
216 command-line arguments for every run (and should probably keep stdout
217 around), so all this should happen automatically for setup scripts}
Greg Wardc392caa2000-04-11 02:00:26 +0000218
Greg Ward6002ffc2000-04-09 20:54:50 +0000219
220\subsection{Splitting the job up}
Greg Ward1ed49ee2000-09-13 00:00:58 +0000221\label{splitting-up}
Greg Ward6002ffc2000-04-09 20:54:50 +0000222
223Running \code{setup.py install} builds and installs all modules in one
Greg Ward14deaae2000-09-11 00:33:15 +0000224run. If you prefer to work incrementally---especially useful if you
225want to customize the build process, or if things are going wrong---you
226can use the setup script to do one thing at a time. This is
Greg Ward3e7b1332000-05-30 03:00:43 +0000227particularly helpful when the build and install will be done by
228different users---e.g., you might want to build a module distribution
229and hand it off to a system administrator for installation (or do it
230yourself, with super-user privileges).
Greg Ward6002ffc2000-04-09 20:54:50 +0000231
232For example, you can build everything in one step, and then install
233everything in a second step, by invoking the setup script twice:
234\begin{verbatim}
235python setup.py build
236python setup.py install
237\end{verbatim}
238(If you do this, you will notice that running the \command{install}
Greg Ward14deaae2000-09-11 00:33:15 +0000239command first runs the \command{build} command, which---in this
240case---quickly notices that it has nothing to do, since everything in
241the \file{build} directory is up-to-date.)
Greg Ward29576562000-03-18 15:11:50 +0000242
Greg Ward14deaae2000-09-11 00:33:15 +0000243You may not need this ability to break things down often if all you do
244is install modules downloaded off the 'net, but it's very handy for more
245advanced tasks. If you get into distributing your own Python modules
246and extensions, you'll run lots of individual Distutils commands on
247their own.
Greg Ward7c1e5f62000-03-10 01:56:58 +0000248
249
Greg Wardc392caa2000-04-11 02:00:26 +0000250\subsection{How building works}
Greg Ward1ed49ee2000-09-13 00:00:58 +0000251\label{how-build-works}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000252
Greg Wardc392caa2000-04-11 02:00:26 +0000253As implied above, the \command{build} command is responsible for putting
254the files to install into a \emph{build directory}. By default, this is
255\file{build} under the distribution root; if you're excessively
256concerned with speed, or want to keep the source tree pristine, you can
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000257change the build directory with the \longprogramopt{build-base} option.
258For example:
Greg Wardc392caa2000-04-11 02:00:26 +0000259\begin{verbatim}
260python setup.py build --build-base=/tmp/pybuild/foo-1.0
261\end{verbatim}
262(Or you could do this permanently with a directive in your system or
263personal Distutils configuration file; see
Greg Warde78298a2000-04-28 17:12:24 +0000264section~\ref{config-files}.) Normally, this isn't necessary.
Greg Wardc392caa2000-04-11 02:00:26 +0000265
266The default layout for the build tree is as follows:
267\begin{verbatim}
268--- build/ --- lib/
269or
270--- build/ --- lib.<plat>/
271 temp.<plat>/
272\end{verbatim}
273where \code{<plat>} expands to a brief description of the current
Greg Ward7ef2ba72000-10-22 01:40:08 +0000274OS/hardware platform and Python version. The first form, with just a
275\file{lib} directory, is used for ``pure module distributions''---that
276is, module distributions that include only pure Python modules. If a
277module distribution contains any extensions (modules written in C/C++),
278then the second form, with two \code{<plat>} directories, is used. In
279that case, the \file{temp.\filevar{plat}} directory holds temporary
280files generated by the compile/link process that don't actually get
281installed. In either case, the \file{lib} (or
Greg Wardc392caa2000-04-11 02:00:26 +0000282\file{lib.\filevar{plat}}) directory contains all Python modules (pure
283Python and extensions) that will be installed.
284
285In the future, more directories will be added to handle Python scripts,
286documentation, binary executables, and whatever else is needed to handle
Greg Wardd5faa7e2000-04-12 01:42:19 +0000287the job of installing Python modules and applications.
Greg Wardc392caa2000-04-11 02:00:26 +0000288
289
290\subsection{How installation works}
Greg Ward1ed49ee2000-09-13 00:00:58 +0000291\label{how-install-works}
Greg Wardc392caa2000-04-11 02:00:26 +0000292
293After the \command{build} command runs (whether you run it explicitly,
294or the \command{install} command does it for you), the work of the
295\command{install} command is relatively simple: all it has to do is copy
296everything under \file{build/lib} (or \file{build/lib.\filevar{plat}})
297to your chosen installation directory.
298
299If you don't choose an installation directory---i.e., if you just run
300\code{setup.py install}---then the \command{install} command installs to
301the standard location for third-party Python modules. This location
302varies by platform and by how you built/installed Python itself. On
Greg Ward7ef2ba72000-10-22 01:40:08 +0000303Unix and Mac~OS, it also depends on whether the module distribution
Greg Wardc392caa2000-04-11 02:00:26 +0000304being installed is pure Python or contains extensions (``non-pure''):
Greg Wardd5faa7e2000-04-12 01:42:19 +0000305\begin{tableiv}{l|l|l|c}{textrm}%
306 {Platform}{Standard installation location}{Default value}{Notes}
307 \lineiv{Unix (pure)}
Fred Drake01df4532000-06-30 03:36:41 +0000308 {\filenq{\filevar{prefix}/lib/python2.0/site-packages}}
309 {\filenq{/usr/local/lib/python2.0/site-packages}}
Greg Ward502d2b42000-04-12 14:20:15 +0000310 {(1)}
Greg Wardd5faa7e2000-04-12 01:42:19 +0000311 \lineiv{Unix (non-pure)}
Fred Drake01df4532000-06-30 03:36:41 +0000312 {\filenq{\filevar{exec-prefix}/lib/python2.0/site-packages}}
313 {\filenq{/usr/local/lib/python2.0/site-packages}}
Greg Ward502d2b42000-04-12 14:20:15 +0000314 {(1)}
Greg Wardd5faa7e2000-04-12 01:42:19 +0000315 \lineiv{Windows}
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000316 {\filenq{\filevar{prefix}}}
Greg Ward4756e5f2000-04-19 22:40:12 +0000317 {\filenq{C:\textbackslash{}Python}}
Greg Ward502d2b42000-04-12 14:20:15 +0000318 {(2)}
Greg Wardd5faa7e2000-04-12 01:42:19 +0000319 \lineiv{Mac~OS (pure)}
Greg Ward7ef2ba72000-10-22 01:40:08 +0000320 {\filenq{\filevar{prefix}:Lib:site-packages}}
321 {\filenq{Python:Lib:site-packages}}
Greg Wardd5faa7e2000-04-12 01:42:19 +0000322 {}
323 \lineiv{Mac~OS (non-pure)}
Greg Ward7ef2ba72000-10-22 01:40:08 +0000324 {\filenq{\filevar{prefix}:Lib:site-packages}}
325 {\filenq{Python:Lib:site-packages}}
Greg Wardd5faa7e2000-04-12 01:42:19 +0000326 {}
327\end{tableiv}
328
329\noindent Notes:
330\begin{description}
Greg Ward502d2b42000-04-12 14:20:15 +0000331\item[(1)] Most Linux distributions include Python as a standard part of
332 the system, so \filevar{prefix} and \filevar{exec-prefix} are usually
333 both \file{/usr} on Linux. If you build Python yourself on Linux (or
334 any Unix-like system), the default \filevar{prefix} and
335 \filevar{exec-prefix} are \file{/usr/local}.
336\item[(2)] The default installation directory on Windows was
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000337 \file{C:\textbackslash{}Program Files\textbackslash{}Python} under
338 Python 1.6a1, 1.5.2, and earlier.
Greg Wardd5faa7e2000-04-12 01:42:19 +0000339\end{description}
340
Greg Wardc392caa2000-04-11 02:00:26 +0000341\filevar{prefix} and \filevar{exec-prefix} stand for the directories
342that Python is installed to, and where it finds its libraries at
343run-time. They are always the same under Windows and Mac~OS, and very
344often the same under Unix. You can find out what your Python
345installation uses for \filevar{prefix} and \filevar{exec-prefix} by
346running Python in interactive mode and typing a few simple commands.
347Under Unix, just type \code{python} at the shell prompt; under Windows,
Fred Drake01df4532000-06-30 03:36:41 +0000348run ``Python 2.0 (interpreter)'' \XXX{right?}; under Mac~OS, \XXX{???}.
349Once the interpreter is started, you type Python code at the
350\samp{>>> } prompt. For example, on my Linux system, I type the three
351Python statements shown below, and get the output as shown, to find
352out my \filevar{prefix} and \filevar{exec-prefix}:
353
Greg Wardc392caa2000-04-11 02:00:26 +0000354\begin{verbatim}
355Python 1.5.2 (#1, Apr 18 1999, 16:03:16) [GCC pgcc-2.91.60 19981201 (egcs-1.1.1 on linux2
356Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
357>>> import sys
358>>> sys.prefix
359'/usr'
360>>> sys.exec_prefix
361'/usr'
362\end{verbatim}
363
Greg Ward7ef2ba72000-10-22 01:40:08 +0000364If you don't want to install modules to the standard location, or if you
365don't have permission to write there, then you need to read about
366alternate installations in section~\ref{alt-install}. If you want to
367customize your installation directories more heavily, see
368section~\ref{custom-install} on custom installations.
Greg Wardc392caa2000-04-11 02:00:26 +0000369
370
371% This rather nasty macro is used to generate the tables that describe
372% each installation scheme. It's nasty because it takes two arguments
373% for each "slot" in an installation scheme, there will soon be more
374% than five of these slots, and TeX has a limit of 10 arguments to a
375% macro. Uh-oh.
376
Greg Ward29576562000-03-18 15:11:50 +0000377\newcommand{\installscheme}[8]
378 {\begin{tableiii}{lll}{textrm}
379 {Type of file}
380 {Installation Directory}
381 {Override option}
382 \lineiii{pure module distribution}
383 {\filevar{#1}\filenq{#2}}
Greg Warda021aca2000-04-19 22:34:11 +0000384 {\longprogramopt{install-purelib}}
Greg Ward29576562000-03-18 15:11:50 +0000385 \lineiii{non-pure module distribution}
386 {\filevar{#3}\filenq{#4}}
Greg Warda021aca2000-04-19 22:34:11 +0000387 {\longprogramopt{install-platlib}}
Greg Ward29576562000-03-18 15:11:50 +0000388 \lineiii{scripts}
389 {\filevar{#5}\filenq{#6}}
Greg Warda021aca2000-04-19 22:34:11 +0000390 {\longprogramopt{install-scripts}}
Greg Ward29576562000-03-18 15:11:50 +0000391 \lineiii{data}
392 {\filevar{#7}\filenq{#8}}
Greg Warda021aca2000-04-19 22:34:11 +0000393 {\longprogramopt{install-data}}
Greg Ward29576562000-03-18 15:11:50 +0000394 \end{tableiii}}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000395
Greg Ward0bc59532000-09-30 21:06:40 +0000396
397\section{Building Extensions: Tips and Tricks}
398\label{building-ext}
399
400(This is the section to read for people doing any sort of interesting
401build. Things to talk about:
402\begin{itemize}
403\item the \file{Setup} file (any platform now, but Unix-biased)
404\item CFLAGS and LDFLAGS (must implement them first!)
405\item using non-MS compilers on Windows (how to convert
406 Python's library, ...)
407\end{itemize}
408
409
410\subsection{Tweaking compiler/linker flags}
411\label{tweak-flags}
412
413
414\subsection{Using non-Microsoft compilers on Windows}
415\label{non-ms-compilers}
416
417\XXX{One place to look: \url{http://www.cyberus.ca/~g_will/pyExtenDL.shtml}}
418
419
420
Greg Ward29576562000-03-18 15:11:50 +0000421\section{Alternate Installation}
Greg Warde78298a2000-04-28 17:12:24 +0000422\label{alt-install}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000423
Greg Ward29576562000-03-18 15:11:50 +0000424Often, it is necessary or desirable to install modules to a location
425other than the standard location for third-party Python modules. For
426example, on a Unix system you might not have permission to write to the
427standard third-party module directory. Or you might wish to try out a
428module before making it a standard part of your local Python
429installation; this is especially true when upgrading a distribution
430already present: you want to make sure your existing base of scripts
431still works with the new version before actually upgrading.
432
433The Distutils \command{install} command is designed to make installing
434module distributions to an alternate location simple and painless. The
435basic idea is that you supply a base directory for the installation, and
436the \command{install} command picks a set of directories (called an
437\emph{installation scheme}) under this base directory in which to
438install files. The details differ across platforms, so read whichever
439of the following section applies to you.
440
441
442\subsection{Alternate installation: Unix (the home scheme)}
Greg Ward1ed49ee2000-09-13 00:00:58 +0000443\label{alt-install-prefix}
Greg Ward29576562000-03-18 15:11:50 +0000444
445Under Unix, there are two ways to perform an alternate installation.
446The ``prefix scheme'' is similar to how alternate installation works
Greg Wardc392caa2000-04-11 02:00:26 +0000447under Windows and Mac~OS, but is not necessarily the most useful way to
Greg Ward29576562000-03-18 15:11:50 +0000448maintain a personal Python library. Hence, we document the more
449convenient and commonly useful ``home scheme'' first.
450
Greg Wardc392caa2000-04-11 02:00:26 +0000451The idea behind the ``home scheme'' is that you build and maintain a
452personal stash of Python modules, probably under your home directory.
453Installing a new module distribution is as simple as
Greg Ward29576562000-03-18 15:11:50 +0000454\begin{verbatim}
455python setup.py install --home=<dir>
456\end{verbatim}
Greg Warda021aca2000-04-19 22:34:11 +0000457where you can supply any directory you like for the \longprogramopt{home}
Greg Ward4756e5f2000-04-19 22:40:12 +0000458option. Lazy typists can just type a tilde (\code{\textasciitilde}); the
Greg Wardc392caa2000-04-11 02:00:26 +0000459\command{install} command will expand this to your home directory:
460\begin{verbatim}
461python setup.py install --home=~
462\end{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000463
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000464The \longprogramopt{home} option defines the installation base
465directory. Files are installed to the following directories under the
466installation base as follows:
Greg Ward29576562000-03-18 15:11:50 +0000467\installscheme{home}{/lib/python}
468 {home}{/lib/python}
469 {home}{/bin}
470 {home}{/share}
471
472\subsection{Alternate installation: Unix (the prefix scheme)}
Greg Ward1ed49ee2000-09-13 00:00:58 +0000473\label{alt-install-home}
Greg Ward29576562000-03-18 15:11:50 +0000474
475The ``prefix scheme'' is useful when you wish to use one Python
476installation to perform the build/install (i.e., to run the setup
477script), but install modules into the third-party module directory of a
478different Python installation (or something that looks like a different
479Python installation). If this sounds a trifle unusual, it is---that's
480why the ``home scheme'' comes first. However, there are at least two
481known cases where the prefix scheme will be useful.
482
Greg Ward19c67f82000-06-24 01:33:16 +0000483First, consider that many Linux distributions put Python in \file{/usr},
Greg Ward29576562000-03-18 15:11:50 +0000484rather than the more traditional \file{/usr/local}. This is entirely
485appropriate, since in those cases Python is part of ``the system''
486rather than a local add-on. However, if you are installing Python
487modules from source, you probably want them to go in
488\file{/usr/local/lib/python1.\filevar{X}} rather than
489\file{/usr/lib/python1.\filevar{X}}. This can be done with
490\begin{verbatim}
491/usr/bin/python setup.py install --prefix=/usr/local
492\end{verbatim}
493
494Another possibility is a network filesystem where the name used to write
495to a remote directory is different from the name used to read it: for
496example, the Python interpreter accessed as \file{/usr/local/bin/python}
497might search for modules in \file{/usr/local/lib/python1.\filevar{X}},
498but those modules would have to be installed to, say,
499\file{/mnt/\filevar{@server}/export/lib/python1.\filevar{X}}. This
500could be done with
501\begin{verbatim}
502/usr/local/bin/python setup.py install --prefix=/mnt/@server/export
503\end{verbatim}
504
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000505In either case, the \longprogramopt{prefix} option defines the
506installation base, and the \longprogramopt{exec-prefix} option defines
507the platform-specific installation base, which is used for
508platform-specific files. (Currently, this just means non-pure module
509distributions, but could be expanded to C libraries, binary executables,
510etc.) If \longprogramopt{exec-prefix} is not supplied, it defaults to
511\longprogramopt{prefix}. Files are installed as follows:
Greg Ward29576562000-03-18 15:11:50 +0000512
513\installscheme{prefix}{/lib/python1.\filevar{X}/site-packages}
514 {exec-prefix}{/lib/python1.\filevar{X}/site-packages}
515 {prefix}{/bin}
516 {prefix}{/share}
517
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000518There is no requirement that \longprogramopt{prefix} or
519\longprogramopt{exec-prefix} actually point to an alternate Python
520installation; if the directories listed above do not already exist, they
521are created at installation time.
Greg Ward29576562000-03-18 15:11:50 +0000522
523Incidentally, the real reason the prefix scheme is important is simply
524that a standard Unix installation uses the prefix scheme, but with
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000525\longprogramopt{prefix} and \longprogramopt{exec-prefix} supplied by
526Python itself (as \code{sys.prefix} and \code{sys.exec\_prefix}). Thus,
527you might think you'll never use the prefix scheme, but every time you
528run \code{python setup.py install} without any other options, you're
529using it.
Greg Ward29576562000-03-18 15:11:50 +0000530
531Note that installing extensions to an alternate Python installation has
532no effect on how those extensions are built: in particular, the Python
533header files (\file{Python.h} and friends) installed with the Python
534interpreter used to run the setup script will be used in compiling
535extensions. It is your responsibility to ensure that the interpreter
536used to run extensions installed in this way is compatibile with the
Greg Wardc392caa2000-04-11 02:00:26 +0000537interpreter used to build them. The best way to do this is to ensure
538that the two interpreters are the same version of Python (possibly
539different builds, or possibly copies of the same build). (Of course, if
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000540your \longprogramopt{prefix} and \longprogramopt{exec-prefix} don't even
541point to an alternate Python installation, this is immaterial.)
Greg Ward29576562000-03-18 15:11:50 +0000542
543
544\subsection{Alternate installation: Windows}
Greg Ward1ed49ee2000-09-13 00:00:58 +0000545\label{alt-install-windows}
Greg Ward29576562000-03-18 15:11:50 +0000546
547Since Windows has no conception of a user's home directory, and since
548the standard Python installation under Windows is simpler than that
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000549under Unix, there's no point in having separate \longprogramopt{prefix}
550and \longprogramopt{home} options. Just use the \longprogramopt{prefix}
551option to specify a base directory, e.g.
Greg Ward29576562000-03-18 15:11:50 +0000552\begin{verbatim}
Greg Ward8e14f052000-03-22 01:00:23 +0000553python setup.py install --prefix="\Temp\Python"
Greg Ward29576562000-03-18 15:11:50 +0000554\end{verbatim}
Greg Ward4756e5f2000-04-19 22:40:12 +0000555to install modules to the \file{\textbackslash{}Temp} directory on the current
Greg Ward29576562000-03-18 15:11:50 +0000556drive.
557
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000558The installation base is defined by the \longprogramopt{prefix} option;
559the \longprogramopt{exec-prefix} option is not supported under Windows.
560Files are installed as follows:
Greg Ward29576562000-03-18 15:11:50 +0000561\installscheme{prefix}{}
562 {prefix}{}
Greg Ward4756e5f2000-04-19 22:40:12 +0000563 {prefix}{\textbackslash{}Scripts}
564 {prefix}{\textbackslash{}Data}
Greg Ward29576562000-03-18 15:11:50 +0000565
566
Greg Wardc392caa2000-04-11 02:00:26 +0000567\subsection{Alternate installation: Mac~OS}
Greg Ward1ed49ee2000-09-13 00:00:58 +0000568\label{alt-install-macos}
Greg Ward29576562000-03-18 15:11:50 +0000569
Greg Wardc392caa2000-04-11 02:00:26 +0000570Like Windows, Mac~OS has no notion of home directories (or even of
Greg Ward29576562000-03-18 15:11:50 +0000571users), and a fairly simple standard Python installation. Thus, only a
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000572\longprogramopt{prefix} option is needed. It defines the installation
573base, and files are installed under it as follows:
Greg Ward29576562000-03-18 15:11:50 +0000574
Greg Ward8c562592000-09-13 00:12:37 +0000575\installscheme{prefix}{:Lib:site-packages}
576 {prefix}{:Lib:site-packages}
Greg Ward8e14f052000-03-22 01:00:23 +0000577 {prefix}{:Scripts}
578 {prefix}{:Data}
Greg Ward29576562000-03-18 15:11:50 +0000579
Greg Ward8c562592000-09-13 00:12:37 +0000580See section~\ref{platform-variations} for information on supplying
581command-line arguments to the setup script with MacPython.
Greg Ward29576562000-03-18 15:11:50 +0000582
583
584\section{Custom Installation}
Greg Warde78298a2000-04-28 17:12:24 +0000585\label{custom-install}
Greg Ward29576562000-03-18 15:11:50 +0000586
587Sometimes, the alternate installation schemes described in
Greg Warde78298a2000-04-28 17:12:24 +0000588section~\ref{alt-install} just don't do what you want. You might
Greg Ward29576562000-03-18 15:11:50 +0000589want to tweak just one or two directories while keeping everything under
590the same base directory, or you might want to completely redefine the
591installation scheme. In either case, you're creating a \emph{custom
592 installation scheme}.
593
594You probably noticed the column of ``override options'' in the tables
595describing the alternate installation schemes above. Those options are
596how you define a custom installation scheme. These override options can
597be relative, absolute, or explicitly defined in terms of one of the
598installation base directories. (There are two installation base
599directories, and they are normally the same---they only differ when you
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000600use the Unix ``prefix scheme'' and supply different
601\longprogramopt{prefix} and \longprogramopt{exec-prefix} options.)
Greg Ward29576562000-03-18 15:11:50 +0000602
603For example, say you're installing a module distribution to your home
604directory under Unix---but you want scripts to go in
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000605\file{\textasciitilde/scripts} rather than \file{\textasciitilde/bin}.
606As you might expect, you can override this directory with the
607\longprogramopt{install-scripts} option; in this case, it makes most
608sense to supply a relative path, which will be interpreted relative to
609the installation base directory (your home directory, in this case):
Greg Ward29576562000-03-18 15:11:50 +0000610\begin{verbatim}
Greg Ward19c67f82000-06-24 01:33:16 +0000611python setup.py install --home=~ --install-scripts=scripts
Greg Ward29576562000-03-18 15:11:50 +0000612\end{verbatim}
613
614Another Unix example: suppose your Python installation was built and
615installed with a prefix of \file{/usr/local/python}, so under a standard
616installation scripts will wind up in \file{/usr/local/python/bin}. If
617you want them in \file{/usr/local/bin} instead, you would supply this
Greg Warda021aca2000-04-19 22:34:11 +0000618absolute directory for the \longprogramopt{install-scripts} option:
Greg Ward29576562000-03-18 15:11:50 +0000619\begin{verbatim}
620python setup.py install --install-scripts=/usr/local/bin
621\end{verbatim}
622(This performs an installation using the ``prefix scheme,'' where the
623prefix is whatever your Python interpreter was installed with---
624\file{/usr/local/python} in this case.)
625
626If you maintain Python on Windows, you might want third-party modules to
627live in a subdirectory of \filevar{prefix}, rather than right in
628\filevar{prefix} itself. This is almost as easy as customizing the
629script installation directory---you just have to remember that there are
630two types of modules to worry about, pure modules and non-pure modules
631(i.e., modules from a non-pure distribution). For example:
632\begin{verbatim}
633python setup.py install --install-purelib=Site --install-platlib=Site
634\end{verbatim}
635The specified installation directories are relative to \filevar{prefix}.
636Of course, you also have to ensure that these directories are in
637Python's module search path, e.g. by putting a \file{.pth} file in
Greg Ward6002ffc2000-04-09 20:54:50 +0000638\filevar{prefix} (\XXX{should have a section describing .pth files and
639 cross-ref it here}).
Greg Ward29576562000-03-18 15:11:50 +0000640
641If you want to define an entire installation scheme, you just have to
642supply all of the installation directory options. The recommended way
Greg Wardc392caa2000-04-11 02:00:26 +0000643to do this is to supply relative paths; for example, if you want to
644maintain all Python module-related files under \file{python} in your
645home directory, and you want a separate directory for each platform that
646you use your home directory from, you might define the following
Greg Ward29576562000-03-18 15:11:50 +0000647installation scheme:
648\begin{verbatim}
Greg Wardc392caa2000-04-11 02:00:26 +0000649python setup.py install --home=~ \
Greg Ward29576562000-03-18 15:11:50 +0000650 --install-purelib=python/lib \
651 --install-platlib=python/lib.$PLAT \
652 --install-scripts=python/scripts
653 --install-data=python/data
654\end{verbatim}
655or, equivalently,
656\begin{verbatim}
657python setup.py install --home=~/python \
658 --install-purelib=lib \
Greg Ward19c67f82000-06-24 01:33:16 +0000659 --install-platlib='lib.$PLAT' \
Greg Ward29576562000-03-18 15:11:50 +0000660 --install-scripts=scripts
661 --install-data=data
662\end{verbatim}
663\code{\$PLAT} is not (necessarily) an environment variable---it will be
664expanded by the Distutils as it parses your command line options (just
665as it does when parsing your configuration file(s)).
666
667Obviously, specifying the entire installation scheme every time you
668install a new module distribution would be very tedious. Thus, you can
669put these options into your Distutils config file (see
Greg Warde78298a2000-04-28 17:12:24 +0000670section~\ref{config-files}):
Greg Ward169f91b2000-03-10 01:57:51 +0000671\begin{verbatim}
672[install]
Greg Ward29576562000-03-18 15:11:50 +0000673install-base=$HOME
674install-purelib=python/lib
675install-platlib=python/lib.$PLAT
676install-scripts=python/scripts
677install-data=python/data
Greg Ward169f91b2000-03-10 01:57:51 +0000678\end{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000679or, equivalently,
Greg Ward169f91b2000-03-10 01:57:51 +0000680\begin{verbatim}
681[install]
Greg Ward29576562000-03-18 15:11:50 +0000682install-base=$HOME/python
683install-purelib=lib
684install-platlib=lib.$PLAT
685install-scripts=scripts
686install-data=data
Greg Ward169f91b2000-03-10 01:57:51 +0000687\end{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000688Note that these two are \emph{not} equivalent if you supply a different
689installation base directory when you run the setup script. For example,
Greg Ward7c1e5f62000-03-10 01:56:58 +0000690\begin{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000691python setup.py --install-base=/tmp
Greg Ward7c1e5f62000-03-10 01:56:58 +0000692\end{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000693would install pure modules to \filevar{/tmp/python/lib} in the first
694case, and to \filevar{/tmp/lib} in the second case. (For the second
695case, you probably want to supply an installation base of
696\file{/tmp/python}.)
Greg Ward169f91b2000-03-10 01:57:51 +0000697
Greg Ward29576562000-03-18 15:11:50 +0000698You probably noticed the use of \code{\$HOME} and \code{\$PLAT} in the
699sample configuration file input. These are Distutils configuration
700variables, which bear a strong resemblance to environment variables. In
Greg Wardc392caa2000-04-11 02:00:26 +0000701fact, you can use environment variables in config files---on platforms
702that have such a notion---but the Distutils additionally define a few
703extra variables that may not be in your environment, such as
704\code{\$PLAT}. (And of course, you can only use the configuration
705variables supplied by the Distutils on systems that don't have
706environment variables, such as Mac~OS (\XXX{true?}).) See
Greg Warde78298a2000-04-28 17:12:24 +0000707section~\ref{config-files} for details.
Greg Ward7c1e5f62000-03-10 01:56:58 +0000708
Greg Wardc392caa2000-04-11 02:00:26 +0000709\XXX{need some Windows and Mac~OS examples---when would custom
Greg Ward6002ffc2000-04-09 20:54:50 +0000710 installation schemes be needed on those platforms?}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000711
Greg Ward7c1e5f62000-03-10 01:56:58 +0000712
Greg Ward6002ffc2000-04-09 20:54:50 +0000713\section{Distutils Configuration Files}
Greg Warde78298a2000-04-28 17:12:24 +0000714\label{config-files}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000715
Greg Ward7ef2ba72000-10-22 01:40:08 +0000716As mentioned above, you can use Distutils configuration files to record
717personal or site preferences for any Distutils options. That is, any
718option to any command can be stored in one of two or three (depending on
719your platform) configuration files, which will be consulted before the
720command-line is parsed. This means that configuration files will
721override default values, and the command-line will in turn override
722configuration files. Furthermore, if multiple configuration files
723apply, values from ``earlier'' files are overridden by ``later'' files.
724
725
726\subsection{Location and names of config files}
727\label{sec:config-filenames}
728
729The names and locations of the configuration files vary slightly across
730platforms. On Unix, the three configuration files (in the order they
731are processed) are:
732\begin{tableiii}{l|l|c}{textrm}
733 {Type of file}{Location and filename}{Notes}
734 \lineiii{system}{\filenq{\filevar{prefix}/lib/python\filevar{ver}/distutils/pydistutils.cfg}}{(1)}
735 \lineiii{personal}{\filenq{\$HOME/.pydistutils.cfg}}{(2)}
736 \lineiii{local}{\filenq{setup.cfg}}{(3)}
737\end{tableiii}
738
739On Windows, the configuration files are:
740\begin{tableiii}{l|l|c}{textrm}
741 {Type of file}{Location and filename}{Notes}
742 \lineiii{system}{\filenq{\filevar{prefix}\textbackslash{}Lib\textbackslash{}distutils\textbackslash{}pydistutils.cfg}}{(4)}
743 \lineiii{personal}{\filenq{\%HOME\textbackslash{}pydistutils.cfg}}{(5)}
744 \lineiii{local}{\filenq{setup.cfg}}{(3)}
745\end{tableiii}
746
747And on Mac~OS, they are:
748\begin{tableiii}{l|l|c}{textrm}
749 {Type of file}{Location and filename}{Notes}
750 \lineiii{system}{\filenq{\filevar{prefix}:Lib:distutils:pydistutils.cfg}}{(6)}
751 \lineiii{personal}{N/A}{}
752 \lineiii{local}{\filenq{setup.cfg}}{(3)}
753\end{tableiii}
754
755\noindent Notes:
756\begin{description}
757\item[(1)] Strictly speaking, the system-wide configuration file lives
758 in the directory where the Distutils are installed; under Python 1.6
759 and later on Unix, this is as shown. For Python 1.5.2, the Distutils
760 will normally be installed to
761 \file{\filevar{prefix}/lib/site-packages/python1.5/distutils},
762 so the system configuration file should be put there under Python
763 1.5.2.
764\item[(2)] On Unix, if the \envvar{HOME} environment variable is not
765 defined, the user's home directory will be determined with the
766 \function{getpwuid()} function from the standard \module{pwd} module.
767\item[(3)] I.e., in the current directory (usually the location of the
768 setup script).
769\item[(4)] (See also note (1).) Under Python 1.6 and later, Python's
770 default ``installation prefix'' is \file{C:\textbackslash{}Python}, so
771 the system configuration file is normally
772 \file{C:\textbackslash{}Python\textbackslash{}Lib\textbackslash{}distutils\textbackslash{}pydistutils.cfg}.
773 Under Python 1.5.2, the default prefix was
774 \file{C:\textbackslash{}Program~Files\textbackslash{}Python}, and the
775 Distutils were not part of the standard library---so the system
776 configuration file would be
777 \file{C:\textbackslash{}Program~Files\textbackslash{}Python\textbackslash{}distutils\textbackslash{}pydistutils.cfg}
778 in a standard Python 1.5.2 installation under Windows.
779\item[(5)] On Windows, if the \envvar{HOME} environment variable is not
780 defined, no personal configuration file will be found or used. (In
781 other words, the Distutils make no attempt to guess your home
782 directory on Windows.)
783\item[(6)] (See also notes (1) and (4).) The default installation
784 prefix is just \file{Python:}, so under Python 1.6 and later this is
785 normally\file{Python:Lib:distutils:pydistutils.cfg}. (The Distutils
786 don't work very well with Python 1.5.2 under Mac~OS. \XXX{true?})
787\end{description}
788
789
790\subsection{Syntax of config files}
791\label{sec:config-syntax}
792
793The Distutils configuration files all have the same syntax. The config
794files are grouped into sections; there is one section for each Distutils
795command, plus a \code{global} section for global options that affect
796every command. Each section consists of one option per line, specified
797like \code{option=value}.
798
799For example, the following is a complete config file that just forces
800all commands to run quietly by default:
801\begin{verbatim}
802[global]
803verbose=0
804\end{verbatim}
805
806If this is installed as the system config file, it will affect all
807processing of any Python module distribution by any user on the current
808system. If it is installed as your personal config file (on systems
809that support them), it will affect only module distributions processed
810by you. And if it is used as the \file{setup.cfg} for a particular
811module distribution, it affects only that distribution.
812
813You could override the default ``build base'' directory and make the
814\command{build*} commands always forcibly rebuild all files with the
815following:
816\begin{verbatim}
817[build]
818build-base=blib
819force=1
820\end{verbatim}
821which corresponds to the command-line arguments
822\begin{verbatim}
823python setup.py build --build-base=blib --force
824\end{verbatim}
825except that including the \command{build} command on the command-line
826means that command will be run. Including a particular command in
827config files has no such implication; it only means that if the command
828is run, the options in the config file will apply. (Or if other
829commands that derive values from it are run, they will use the values in
830the config file.)
831
832You can find out the complete list of options for any command using the
833\longprogramopt{help} option, e.g.:
834\begin{verbatim}
835python setup.py build --help
836\end{verbatim}
837and you can find out the complete list of global options by using
838\longprogramopt{help} without a command:
839\begin{verbatim}
840python setup.py --help
841\end{verbatim}
842See also the ``Reference'' section of the ``Distributing Python
843Modules'' manual.
844
Greg Ward6002ffc2000-04-09 20:54:50 +0000845
846\section{Pre-Distutils Conventions}
Greg Warde78298a2000-04-28 17:12:24 +0000847\label{pre-distutils}
Greg Ward6002ffc2000-04-09 20:54:50 +0000848
849
Greg Wardc392caa2000-04-11 02:00:26 +0000850\subsection{The Makefile.pre.in file}
Greg Warde78298a2000-04-28 17:12:24 +0000851\label{makefile-pre-in}
Greg Ward6002ffc2000-04-09 20:54:50 +0000852
853
854\subsection{Installing modules manually}
Greg Warde78298a2000-04-28 17:12:24 +0000855\label{manual-install}
Greg Ward6002ffc2000-04-09 20:54:50 +0000856
857
858
Greg Ward7c1e5f62000-03-10 01:56:58 +0000859\end{document}