blob: 673d48d5d71a6e26a1fbd5df8c41e6dc0c8fedc3 [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 Ward7c1e5f62000-03-10 01:56:58 +000027
28\begin{document}
29
30\maketitle
31
32%\begin{abstract}
33%\noindent
34%Abstract this!
35%\end{abstract}
36
37\tableofcontents
38
39\section{Introduction}
40\label{sec:intro}
41
Greg Ward6002ffc2000-04-09 20:54:50 +000042Although Python's extensive standard library covers many programming
43needs, there often comes a time when you need to add some new
44functionality to your Python installation in the form of third-party
45modules. This might be necessary to support your own programming, or to
46support an application that you want to use and that happens to be
47written in Python.
48
49In the past, there has been little support for adding third-party
50modules to an existing Python installation. With the introduction of
51the Python Distribution Utilities (Distutils for short) in Python 1.6,
52this is starting to change. Not everything will change overnight,
53though, so while this document concentrates on installing module
54distributions that use the Distutils, we will also spend some time
55dealing with the old ways.
56
57This document is aimed primarily at the people who need to install
58third-party Python modules: end-users and system administrators who just
59need to get some Python application running, and existing Python
60programmers who want to add some new goodies to their toolbox. You
61don't need to know Python to read this document; there will be some
62brief forays into using Python's interactive mode to explore your
63installation, but that's it. If you're looking for information on how
64to distribute your own Python modules so that others may use them, see
65the ``Distributing Python Modules'' manual.
Greg Ward7c1e5f62000-03-10 01:56:58 +000066
67
Greg Ward6002ffc2000-04-09 20:54:50 +000068\subsection{Best case: trivial installation}
69\label{sec:trivial-inst}
70
71In the best case, someone will have prepared a special version of the
72module distribution you want to install that is targeted specifically at
73your platform and is installed just like any other software on your
74platform. For example, the module developer might make an executable
75installer available for Windows users, an RPM package for users of
76RPM-based Linux systems (Red Hat, SuSE, Mandrake, and many others), a
77Debian package for users of Debian-based Linux systems (Debian proper,
78Caldera, Corel, etc.), and so forth.
79
80In that case, you would download the installer appropriate to your
Greg Wardc392caa2000-04-11 02:00:26 +000081platform and do the obvious thing with it: run it if it's an executable
82installer, \code{rpm --install} it if it's an RPM, etc. You don't need
83to run Python or a setup script, you don't need to compile
84anything---you might not even need to read any instructions (although
85it's always a good idea to do so anyways).
Greg Ward6002ffc2000-04-09 20:54:50 +000086
87Of course, things will not always be that easy. You might be interested
Greg Wardc392caa2000-04-11 02:00:26 +000088in a module distribution that doesn't have an easy-to-use installer for
89your platform. In that case, you'll have to start with the source
90distribution released by the module's author/maintainer. Installing
91from a source distribution is not too hard, as long as the modules are
92packaged in the standard way. The bulk of this document is about
93building and installing modules from standard source distributions.
Greg Ward7c1e5f62000-03-10 01:56:58 +000094
95
Greg Ward6002ffc2000-04-09 20:54:50 +000096\subsection{The new standard: Distutils}
97\label{sec:new-standard}
98
99If you download a module source distribution, you can tell pretty
100quickly if was packaged and distributed in the standard way, i.e. using
101the Distutils. First, the distribution's name and version number will
102be featured prominently in the name of the downloaded archive, e.g.
103\file{foo-1.0.tar.gz} or \file{widget-0.9.7.zip}. Next, the archive
104will unpack into a similarly-named directory: \file{foo-1.0} or
105\file{widget-0.9.7}. Additionally, the distribution will contain a
106setup script \file{setup.py}, and a \file{README.txt} (or possibly
107\file{README}), which should explain that building and installing the
108module distribution is a simple matter of running
109\begin{verbatim}
110python setup.py install
111\end{verbatim}
112
113If all these things are true, then you already know how to build and
114install the modules you've just downloaded: run the command above.
115Unless you need to install things in a non-standard way or customize the
116build process, you don't really need this manual. Or rather, the above
117command is everything you need to get out of this manual.
Greg Ward7c1e5f62000-03-10 01:56:58 +0000118
119
Greg Ward6002ffc2000-04-09 20:54:50 +0000120\subsection{The old way: no standards}
121\label{sec:old-way}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000122
Greg Ward6002ffc2000-04-09 20:54:50 +0000123Before the Distutils, there was no infrastructure to support installing
124third-party modules in a consistent, standardized way. Thus, it's not
125really possible to write a general manual for installing Python modules
126that don't use the Distutils; the only truly general statement that can
Greg Wardc392caa2000-04-11 02:00:26 +0000127be made is, ``Read the module's own installation instructions.''
Greg Ward6002ffc2000-04-09 20:54:50 +0000128
Greg Wardc392caa2000-04-11 02:00:26 +0000129However, if such instructions exists at all, they are often woefully
130inadequate and targeted at experienced Python developers. Such users
131are already familiar with how the Python library is laid out on their
132platform, and know where to copy various files in order for Python to
133find them. This document makes no such assumptions, and explains how
134the Python library is laid out on three major platforms (Unix, Windows,
135and Mac~OS), so that you can understand what happens when the Distutils
136do their job \emph{and} know how to install modules manually when the
137module author fails to provide a setup script.
Greg Ward6002ffc2000-04-09 20:54:50 +0000138
139Additionally, while there has not previously been a standard
140installation mechanism, Python has had some standard machinery for
141building extensions on Unix since Python \XXX{version?}. This machinery
142(the \file{Makefile.pre.in} file) is superseded by the Distutils, but it
143will no doubt live on in older module distributions for a while. This
144\file{Makefile.pre.in} mechanism is documented in the ``Extending \&
145Embedding Python'' manual, but that manual is aimed at module
146developers---hence, we include documentation for builders/installers
147here.
148
149All of the pre-Distutils material is tucked away in
150section~\ref{sec:pre-distutils}.
Greg Ward7c1e5f62000-03-10 01:56:58 +0000151
152
Greg Ward29576562000-03-18 15:11:50 +0000153\section{Standard Build and Install}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000154\label{sec:normal-install}
155
Greg Ward6002ffc2000-04-09 20:54:50 +0000156As described in section~\ref{sec:new-standard}, building and installing
157a module distribution using the Distutils is usually one simple command:
158\begin{verbatim}
159python setup.py install
160\end{verbatim}
161On Unix, you'd run this command from a shell prompt; on Windows, you
Greg Wardc392caa2000-04-11 02:00:26 +0000162have to open a command prompt window and do it there; on Mac~OS ...
163\XXX{what the heck do you do on Mac~OS?}.
Greg Ward6002ffc2000-04-09 20:54:50 +0000164
165
166\subsection{Platform variations}
167
168You should always run the setup command from the distribution root
169directory, i.e. the top-level subdirectory that the module source
170distribution unpacks into. For example, if you've just downloaded a
171module source distribution \file{foo-1.0.tar.gz} onto a Unix system, the
172normal thing to do is:
173\begin{verbatim}
174gunzip -c foo-1.0.tar.gz | tar xf - # unpacks into directory foo-1.0
175cd foo-1.0
176python setup.py install
177\end{verbatim}
178
Greg Wardc392caa2000-04-11 02:00:26 +0000179On Windows, you'd probably unpack the archive before opening the command
180prompt. If you downloaded the archive file to \file{C:\bslash{}Temp},
181then it probably unpacked (depending on your software) into
182\file{C:\bslash{}Temp\bslash{}foo-1.0}; from the command prompt window,
183you would then run
Greg Ward6002ffc2000-04-09 20:54:50 +0000184\begin{verbatim}
185cd c:\temp\foo-1.0
186python setup.py install
187\end{verbatim}
188
Greg Wardc392caa2000-04-11 02:00:26 +0000189On Mac~OS, ... \XXX{again, how do you run Python scripts on Mac~OS?}
190
191\XXX{arg, my lovely ``bslash'' macro doesn't work in non-tt fonts! help
192 me \LaTeX, you're my only hope...}
Greg Ward6002ffc2000-04-09 20:54:50 +0000193
194
195\subsection{Splitting the job up}
196
197Running \code{setup.py install} builds and installs all modules in one
198fell swoop. If you prefer to work incrementally---especially useful if
199you want to customize the build process, or if things are going
200wrong---you can use the setup script to do one thing at a time.
201
202For example, you can build everything in one step, and then install
203everything in a second step, by invoking the setup script twice:
204\begin{verbatim}
205python setup.py build
206python setup.py install
207\end{verbatim}
208(If you do this, you will notice that running the \command{install}
Greg Wardc392caa2000-04-11 02:00:26 +0000209command first runs the \command{build} command, which quickly notices
210that it has nothing to do, since everything in the \file{build}
211directory is up-to-date.)
Greg Ward29576562000-03-18 15:11:50 +0000212
Greg Wardc392caa2000-04-11 02:00:26 +0000213\XXX{concrete reason for splitting things up?}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000214
215
Greg Wardc392caa2000-04-11 02:00:26 +0000216\subsection{How building works}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000217
Greg Wardc392caa2000-04-11 02:00:26 +0000218As implied above, the \command{build} command is responsible for putting
219the files to install into a \emph{build directory}. By default, this is
220\file{build} under the distribution root; if you're excessively
221concerned with speed, or want to keep the source tree pristine, you can
222change the build directory with the \option{--build-base} option. For
223example:
224\begin{verbatim}
225python setup.py build --build-base=/tmp/pybuild/foo-1.0
226\end{verbatim}
227(Or you could do this permanently with a directive in your system or
228personal Distutils configuration file; see
229section~\ref{sec:config-files}.) Normally, this isn't necessary.
230
231The default layout for the build tree is as follows:
232\begin{verbatim}
233--- build/ --- lib/
234or
235--- build/ --- lib.<plat>/
236 temp.<plat>/
237\end{verbatim}
238where \code{<plat>} expands to a brief description of the current
239OS/hardware platform. The first form, with just a \file{lib} directory,
240is used for ``pure module distributions''---that is, module
241distributions that include only pure Python modules. If a module
242distribution contains any extensions (modules written in C/C++, or Java
243for JPython), then the second form, with two \code{<plat>} directories,
244is used. In that case, the \file{temp.\filevar{plat}} directory holds
245temporary files generated by the compile/link process that don't
246actually get installed. In either case, the \file{lib} (or
247\file{lib.\filevar{plat}}) directory contains all Python modules (pure
248Python and extensions) that will be installed.
249
250In the future, more directories will be added to handle Python scripts,
251documentation, binary executables, and whatever else is needed to handle
Greg Wardd5faa7e2000-04-12 01:42:19 +0000252the job of installing Python modules and applications.
Greg Wardc392caa2000-04-11 02:00:26 +0000253
254
255\subsection{How installation works}
256
257After the \command{build} command runs (whether you run it explicitly,
258or the \command{install} command does it for you), the work of the
259\command{install} command is relatively simple: all it has to do is copy
260everything under \file{build/lib} (or \file{build/lib.\filevar{plat}})
261to your chosen installation directory.
262
263If you don't choose an installation directory---i.e., if you just run
264\code{setup.py install}---then the \command{install} command installs to
265the standard location for third-party Python modules. This location
266varies by platform and by how you built/installed Python itself. On
267Unix and Mac OS, it also depends on whether the module distribution
268being installed is pure Python or contains extensions (``non-pure''):
Greg Wardd5faa7e2000-04-12 01:42:19 +0000269\begin{tableiv}{l|l|l|c}{textrm}%
270 {Platform}{Standard installation location}{Default value}{Notes}
271 \lineiv{Unix (pure)}
272 {\filenq{\var{prefix}/lib/python1.6/site-packages}}
273 {\filenq{/usr/local/lib/python1.6/site-packages}}
274 {}
275 \lineiv{Unix (non-pure)}
276 {\filenq{\var{exec-prefix}/lib/python1.6/site-packages}}
277 {\filenq{/usr/local/lib/python1.6/site-packages}}
278 {}
279 \lineiv{Windows}
280 {\filenq{\var{prefix}}}
281 {\filenq{C:\bslash{}Python}}
282 {(1)}
283 \lineiv{Mac~OS (pure)}
284 {\filenq{\var{prefix}:Lib}}
285 {\filenq{Python:Lib} \XXX{???}}
286 {}
287 \lineiv{Mac~OS (non-pure)}
288 {\var{prefix}:Mac:PlugIns}
289 {\filenq{Python:Mac:PlugIns}\XXX{???}}
290 {}
291\end{tableiv}
292
293\noindent Notes:
294\begin{description}
295\item[(1)] The default installation directory on Windows was
296 \file{C:\bslash{}Program Files\bslash{}Python} under Python 1.6a1,
297 1.5.2, and earlier.
298\end{description}
299
Greg Wardc392caa2000-04-11 02:00:26 +0000300\filevar{prefix} and \filevar{exec-prefix} stand for the directories
301that Python is installed to, and where it finds its libraries at
302run-time. They are always the same under Windows and Mac~OS, and very
303often the same under Unix. You can find out what your Python
304installation uses for \filevar{prefix} and \filevar{exec-prefix} by
305running Python in interactive mode and typing a few simple commands.
306Under Unix, just type \code{python} at the shell prompt; under Windows,
307run ``Python 1.6 (interpreter)'' \XXX{right?}; under Mac~OS, \XXX{???}.
308Once the interpreter is started, you type Python code at the \code{>>>}
309prompt. For example, on my Linux system, I type the three Python
310statements shown below, and get the output as shown, to find out my
311\filevar{prefix} and \filevar{exec-prefix}:
312\begin{verbatim}
313Python 1.5.2 (#1, Apr 18 1999, 16:03:16) [GCC pgcc-2.91.60 19981201 (egcs-1.1.1 on linux2
314Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
315>>> import sys
316>>> sys.prefix
317'/usr'
318>>> sys.exec_prefix
319'/usr'
320\end{verbatim}
321
322If you don't want to install to the standard location, or if you don't
323have permission to write there, then you need to read about alternate
324installations in the next section.
325
326
327% This rather nasty macro is used to generate the tables that describe
328% each installation scheme. It's nasty because it takes two arguments
329% for each "slot" in an installation scheme, there will soon be more
330% than five of these slots, and TeX has a limit of 10 arguments to a
331% macro. Uh-oh.
332
Greg Ward29576562000-03-18 15:11:50 +0000333\newcommand{\installscheme}[8]
334 {\begin{tableiii}{lll}{textrm}
335 {Type of file}
336 {Installation Directory}
337 {Override option}
338 \lineiii{pure module distribution}
339 {\filevar{#1}\filenq{#2}}
Greg Wardc392caa2000-04-11 02:00:26 +0000340 {\option{--install-purelib}}
Greg Ward29576562000-03-18 15:11:50 +0000341 \lineiii{non-pure module distribution}
342 {\filevar{#3}\filenq{#4}}
Greg Wardc392caa2000-04-11 02:00:26 +0000343 {\option{--install-platlib}}
Greg Ward29576562000-03-18 15:11:50 +0000344 \lineiii{scripts}
345 {\filevar{#5}\filenq{#6}}
Greg Wardc392caa2000-04-11 02:00:26 +0000346 {\option{--install-scripts}}
Greg Ward29576562000-03-18 15:11:50 +0000347 \lineiii{data}
348 {\filevar{#7}\filenq{#8}}
Greg Wardc392caa2000-04-11 02:00:26 +0000349 {\option{--install-data}}
Greg Ward29576562000-03-18 15:11:50 +0000350 \end{tableiii}}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000351
Greg Ward29576562000-03-18 15:11:50 +0000352\section{Alternate Installation}
353\label{sec:alt-install}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000354
Greg Ward29576562000-03-18 15:11:50 +0000355Often, it is necessary or desirable to install modules to a location
356other than the standard location for third-party Python modules. For
357example, on a Unix system you might not have permission to write to the
358standard third-party module directory. Or you might wish to try out a
359module before making it a standard part of your local Python
360installation; this is especially true when upgrading a distribution
361already present: you want to make sure your existing base of scripts
362still works with the new version before actually upgrading.
363
364The Distutils \command{install} command is designed to make installing
365module distributions to an alternate location simple and painless. The
366basic idea is that you supply a base directory for the installation, and
367the \command{install} command picks a set of directories (called an
368\emph{installation scheme}) under this base directory in which to
369install files. The details differ across platforms, so read whichever
370of the following section applies to you.
371
372
373\subsection{Alternate installation: Unix (the home scheme)}
374\label{sec:alt-unix-prefix}
375
376Under Unix, there are two ways to perform an alternate installation.
377The ``prefix scheme'' is similar to how alternate installation works
Greg Wardc392caa2000-04-11 02:00:26 +0000378under Windows and Mac~OS, but is not necessarily the most useful way to
Greg Ward29576562000-03-18 15:11:50 +0000379maintain a personal Python library. Hence, we document the more
380convenient and commonly useful ``home scheme'' first.
381
Greg Wardc392caa2000-04-11 02:00:26 +0000382The idea behind the ``home scheme'' is that you build and maintain a
383personal stash of Python modules, probably under your home directory.
384Installing a new module distribution is as simple as
Greg Ward29576562000-03-18 15:11:50 +0000385\begin{verbatim}
386python setup.py install --home=<dir>
387\end{verbatim}
388where you can supply any directory you like for the \option{home}
Greg Wardc392caa2000-04-11 02:00:26 +0000389option. Lazy typists can just type a tilde (\code{\tilde}); the
390\command{install} command will expand this to your home directory:
391\begin{verbatim}
392python setup.py install --home=~
393\end{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000394
395The \option{home} option defines the installation base directory. Files
396are installed to the following directories under the installation base
397as follows:
398\installscheme{home}{/lib/python}
399 {home}{/lib/python}
400 {home}{/bin}
401 {home}{/share}
402
403\subsection{Alternate installation: Unix (the prefix scheme)}
404\label{sec:alt-unix-home}
405
406The ``prefix scheme'' is useful when you wish to use one Python
407installation to perform the build/install (i.e., to run the setup
408script), but install modules into the third-party module directory of a
409different Python installation (or something that looks like a different
410Python installation). If this sounds a trifle unusual, it is---that's
411why the ``home scheme'' comes first. However, there are at least two
412known cases where the prefix scheme will be useful.
413
414First, consider that many Linux distribution put Python in \file{/usr},
415rather than the more traditional \file{/usr/local}. This is entirely
416appropriate, since in those cases Python is part of ``the system''
417rather than a local add-on. However, if you are installing Python
418modules from source, you probably want them to go in
419\file{/usr/local/lib/python1.\filevar{X}} rather than
420\file{/usr/lib/python1.\filevar{X}}. This can be done with
421\begin{verbatim}
422/usr/bin/python setup.py install --prefix=/usr/local
423\end{verbatim}
424
425Another possibility is a network filesystem where the name used to write
426to a remote directory is different from the name used to read it: for
427example, the Python interpreter accessed as \file{/usr/local/bin/python}
428might search for modules in \file{/usr/local/lib/python1.\filevar{X}},
429but those modules would have to be installed to, say,
430\file{/mnt/\filevar{@server}/export/lib/python1.\filevar{X}}. This
431could be done with
432\begin{verbatim}
433/usr/local/bin/python setup.py install --prefix=/mnt/@server/export
434\end{verbatim}
435
436In either case, the \option{prefix} option defines the installation
437base, and the \option{exec-prefix} option defines the platform-specific
438installation base, which is used for platform-specific files.
439(Currently, this just means non-pure module distributions, but could be
440expanded to C libraries, binary executables, etc.) If
441\option{exec-prefix} is not supplied, it defaults to \option{prefix}.
442Files are installed as follows:
443
444\installscheme{prefix}{/lib/python1.\filevar{X}/site-packages}
445 {exec-prefix}{/lib/python1.\filevar{X}/site-packages}
446 {prefix}{/bin}
447 {prefix}{/share}
448
449There is no requirement that \option{prefix} or \option{exec-prefix}
450actually point to an alternate Python installation; if the directories
451listed above do not already exist, they are created at installation
452time.
453
454Incidentally, the real reason the prefix scheme is important is simply
455that a standard Unix installation uses the prefix scheme, but with
456\option{prefix} and \option{exec-prefix} supplied by Python itself (as
457\code{sys.prefix} and \code{sys.exec\_prefix}). Thus, you might think
458you'll never use the prefix scheme, but every time you run \code{python
459 setup.py install} without any other options, you're using it.
460
461Note that installing extensions to an alternate Python installation has
462no effect on how those extensions are built: in particular, the Python
463header files (\file{Python.h} and friends) installed with the Python
464interpreter used to run the setup script will be used in compiling
465extensions. It is your responsibility to ensure that the interpreter
466used to run extensions installed in this way is compatibile with the
Greg Wardc392caa2000-04-11 02:00:26 +0000467interpreter used to build them. The best way to do this is to ensure
468that the two interpreters are the same version of Python (possibly
469different builds, or possibly copies of the same build). (Of course, if
470your \option{prefix} and \option{exec-prefix} don't even point to an
Greg Ward29576562000-03-18 15:11:50 +0000471alternate Python installation, this is immaterial.)
472
473
474\subsection{Alternate installation: Windows}
475\label{sec:alt-windows}
476
477Since Windows has no conception of a user's home directory, and since
478the standard Python installation under Windows is simpler than that
479under Unix, there's no point in having separate \option{prefix} and
480\option{home} options. Just use the \option{prefix} option to specify
481a base directory, e.g.
482\begin{verbatim}
Greg Ward8e14f052000-03-22 01:00:23 +0000483python setup.py install --prefix="\Temp\Python"
Greg Ward29576562000-03-18 15:11:50 +0000484\end{verbatim}
485to install modules to the \file{\bslash{}Temp} directory on the current
486drive.
487
488The installation base is defined by the \option{prefix} option; the
489\option{exec-prefix} option is not supported under Windows. Files are
490installed as follows:
491\installscheme{prefix}{}
492 {prefix}{}
493 {prefix}{\bslash{}Scripts}
494 {prefix}{\bslash{}Data}
495
496
Greg Wardc392caa2000-04-11 02:00:26 +0000497\subsection{Alternate installation: Mac~OS}
Greg Ward29576562000-03-18 15:11:50 +0000498\label{sec:alt-macos}
499
Greg Wardc392caa2000-04-11 02:00:26 +0000500Like Windows, Mac~OS has no notion of home directories (or even of
Greg Ward29576562000-03-18 15:11:50 +0000501users), and a fairly simple standard Python installation. Thus, only a
502\option{prefix} option is needed. It defines the installation base, and
503files are installed under it as follows:
504
Greg Ward6002ffc2000-04-09 20:54:50 +0000505\XXX{how do MacPython users run the interpreter with command-line args?}
Greg Ward29576562000-03-18 15:11:50 +0000506
507\installscheme{prefix}{:Lib}
508 {prefix}{:Mac:PlugIns}
Greg Ward8e14f052000-03-22 01:00:23 +0000509 {prefix}{:Scripts}
510 {prefix}{:Data}
Greg Ward29576562000-03-18 15:11:50 +0000511
Greg Ward6002ffc2000-04-09 20:54:50 +0000512\XXX{Corran Webster says: ``Modules are found in either \file{:Lib} or
Greg Ward29576562000-03-18 15:11:50 +0000513\file{:Mac:Lib}, while extensions usually go in
514\file{:Mac:PlugIns}''---does this mean that non-pure distributions should
515be divided between \file{:Mac:PlugIns} and \file{:Mac:Lib}? If so, that
516changes the granularity at which we care about modules: instead of
517``modules from pure distributions'' and ``modules from non-pure
518distributions'', it becomes ``modules from pure distributions'',
519``Python modules from non-pure distributions'', and ``extensions from
Greg Ward6002ffc2000-04-09 20:54:50 +0000520non-pure distributions''. Is this necessary?!?}
Greg Ward29576562000-03-18 15:11:50 +0000521
522
523\section{Custom Installation}
524\label{sec:custom-install}
525
526Sometimes, the alternate installation schemes described in
527section~\ref{sec:alt-install} just don't do what you want. You might
528want to tweak just one or two directories while keeping everything under
529the same base directory, or you might want to completely redefine the
530installation scheme. In either case, you're creating a \emph{custom
531 installation scheme}.
532
533You probably noticed the column of ``override options'' in the tables
534describing the alternate installation schemes above. Those options are
535how you define a custom installation scheme. These override options can
536be relative, absolute, or explicitly defined in terms of one of the
537installation base directories. (There are two installation base
538directories, and they are normally the same---they only differ when you
539use the Unix ``prefix scheme'' and supply different \option{prefix} and
540\option{exec-prefix} options.)
541
542For example, say you're installing a module distribution to your home
543directory under Unix---but you want scripts to go in
544\file{\tilde/scripts} rather than \file{\tilde/bin}. As you might
545expect, you can override this directory with the
546\option{install-scripts} option; in this case, it makes most sense to
547supply a relative path, which will be interpreted relative to the
548installation base directory (your home directory, in this case):
549\begin{verbatim}
550python setup.py install --home --install-scripts=scripts
551\end{verbatim}
552
553Another Unix example: suppose your Python installation was built and
554installed with a prefix of \file{/usr/local/python}, so under a standard
555installation scripts will wind up in \file{/usr/local/python/bin}. If
556you want them in \file{/usr/local/bin} instead, you would supply this
557absolute directory for the \option{install-scripts} option:
558\begin{verbatim}
559python setup.py install --install-scripts=/usr/local/bin
560\end{verbatim}
561(This performs an installation using the ``prefix scheme,'' where the
562prefix is whatever your Python interpreter was installed with---
563\file{/usr/local/python} in this case.)
564
565If you maintain Python on Windows, you might want third-party modules to
566live in a subdirectory of \filevar{prefix}, rather than right in
567\filevar{prefix} itself. This is almost as easy as customizing the
568script installation directory---you just have to remember that there are
569two types of modules to worry about, pure modules and non-pure modules
570(i.e., modules from a non-pure distribution). For example:
571\begin{verbatim}
572python setup.py install --install-purelib=Site --install-platlib=Site
573\end{verbatim}
574The specified installation directories are relative to \filevar{prefix}.
575Of course, you also have to ensure that these directories are in
576Python's module search path, e.g. by putting a \file{.pth} file in
Greg Ward6002ffc2000-04-09 20:54:50 +0000577\filevar{prefix} (\XXX{should have a section describing .pth files and
578 cross-ref it here}).
Greg Ward29576562000-03-18 15:11:50 +0000579
580If you want to define an entire installation scheme, you just have to
581supply all of the installation directory options. The recommended way
Greg Wardc392caa2000-04-11 02:00:26 +0000582to do this is to supply relative paths; for example, if you want to
583maintain all Python module-related files under \file{python} in your
584home directory, and you want a separate directory for each platform that
585you use your home directory from, you might define the following
Greg Ward29576562000-03-18 15:11:50 +0000586installation scheme:
587\begin{verbatim}
Greg Wardc392caa2000-04-11 02:00:26 +0000588python setup.py install --home=~ \
Greg Ward29576562000-03-18 15:11:50 +0000589 --install-purelib=python/lib \
590 --install-platlib=python/lib.$PLAT \
591 --install-scripts=python/scripts
592 --install-data=python/data
593\end{verbatim}
594or, equivalently,
595\begin{verbatim}
596python setup.py install --home=~/python \
597 --install-purelib=lib \
598 --install-platlib=lib.$PLAT \
599 --install-scripts=scripts
600 --install-data=data
601\end{verbatim}
602\code{\$PLAT} is not (necessarily) an environment variable---it will be
603expanded by the Distutils as it parses your command line options (just
604as it does when parsing your configuration file(s)).
605
606Obviously, specifying the entire installation scheme every time you
607install a new module distribution would be very tedious. Thus, you can
608put these options into your Distutils config file (see
609section~\ref{sec:config-files}):
Greg Ward169f91b2000-03-10 01:57:51 +0000610\begin{verbatim}
611[install]
Greg Ward29576562000-03-18 15:11:50 +0000612install-base=$HOME
613install-purelib=python/lib
614install-platlib=python/lib.$PLAT
615install-scripts=python/scripts
616install-data=python/data
Greg Ward169f91b2000-03-10 01:57:51 +0000617\end{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000618or, equivalently,
Greg Ward169f91b2000-03-10 01:57:51 +0000619\begin{verbatim}
620[install]
Greg Ward29576562000-03-18 15:11:50 +0000621install-base=$HOME/python
622install-purelib=lib
623install-platlib=lib.$PLAT
624install-scripts=scripts
625install-data=data
Greg Ward169f91b2000-03-10 01:57:51 +0000626\end{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000627Note that these two are \emph{not} equivalent if you supply a different
628installation base directory when you run the setup script. For example,
Greg Ward7c1e5f62000-03-10 01:56:58 +0000629\begin{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000630python setup.py --install-base=/tmp
Greg Ward7c1e5f62000-03-10 01:56:58 +0000631\end{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000632would install pure modules to \filevar{/tmp/python/lib} in the first
633case, and to \filevar{/tmp/lib} in the second case. (For the second
634case, you probably want to supply an installation base of
635\file{/tmp/python}.)
Greg Ward169f91b2000-03-10 01:57:51 +0000636
Greg Ward29576562000-03-18 15:11:50 +0000637You probably noticed the use of \code{\$HOME} and \code{\$PLAT} in the
638sample configuration file input. These are Distutils configuration
639variables, which bear a strong resemblance to environment variables. In
Greg Wardc392caa2000-04-11 02:00:26 +0000640fact, you can use environment variables in config files---on platforms
641that have such a notion---but the Distutils additionally define a few
642extra variables that may not be in your environment, such as
643\code{\$PLAT}. (And of course, you can only use the configuration
644variables supplied by the Distutils on systems that don't have
645environment variables, such as Mac~OS (\XXX{true?}).) See
Greg Ward29576562000-03-18 15:11:50 +0000646section~\ref{sec:config-files} for details.
Greg Ward7c1e5f62000-03-10 01:56:58 +0000647
Greg Wardc392caa2000-04-11 02:00:26 +0000648\XXX{need some Windows and Mac~OS examples---when would custom
Greg Ward6002ffc2000-04-09 20:54:50 +0000649 installation schemes be needed on those platforms?}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000650
Greg Ward7c1e5f62000-03-10 01:56:58 +0000651
Greg Ward6002ffc2000-04-09 20:54:50 +0000652\section{Distutils Configuration Files}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000653\label{sec:config-files}
654
Greg Wardc392caa2000-04-11 02:00:26 +0000655\XXX{not even implemented yet, much less documented!}
Greg Ward6002ffc2000-04-09 20:54:50 +0000656
657
658\section{Pre-Distutils Conventions}
659\label{sec:pre-distutils}
660
661
Greg Wardc392caa2000-04-11 02:00:26 +0000662\subsection{The Makefile.pre.in file}
Greg Ward6002ffc2000-04-09 20:54:50 +0000663\label{sec:makefile-pre-in}
664
665
666\subsection{Installing modules manually}
667\label{sec:manual-install}
668
669
670
Greg Ward7c1e5f62000-03-10 01:56:58 +0000671\end{document}