blob: 967df55b961bbbd8f4c99acb4ab8485eb91cc71b [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 Warde78298a2000-04-28 17:12:24 +000078\label{trivial-inst}
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 Warde78298a2000-04-28 17:12:24 +0000163\label{normal-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 Wardc392caa2000-04-11 02:00:26 +0000171have to open a command prompt window and do it there; on Mac~OS ...
172\XXX{what the heck do you do on Mac~OS?}.
Greg Ward6002ffc2000-04-09 20:54:50 +0000173
174
175\subsection{Platform variations}
176
177You should always run the setup command from the distribution root
178directory, i.e. the top-level subdirectory that the module source
179distribution unpacks into. For example, if you've just downloaded a
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000180module source distribution \file{foo-1.0.tar.gz} onto a Unix system, the
Greg Ward6002ffc2000-04-09 20:54:50 +0000181normal thing to do is:
182\begin{verbatim}
183gunzip -c foo-1.0.tar.gz | tar xf - # unpacks into directory foo-1.0
184cd foo-1.0
185python setup.py install
186\end{verbatim}
187
Greg Wardc392caa2000-04-11 02:00:26 +0000188On Windows, you'd probably unpack the archive before opening the command
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000189prompt. If you downloaded the archive file to
190\file{C:\textbackslash{}Temp}, then it probably unpacked (depending on
191your software) into
192\file{C:\textbackslash{}Temp\textbackslash{}foo-1.0}; from the command
193prompt window, you would then run
Greg Ward6002ffc2000-04-09 20:54:50 +0000194\begin{verbatim}
195cd c:\temp\foo-1.0
196python setup.py install
197\end{verbatim}
198
Greg Wardc392caa2000-04-11 02:00:26 +0000199On Mac~OS, ... \XXX{again, how do you run Python scripts on Mac~OS?}
200
Greg Ward6002ffc2000-04-09 20:54:50 +0000201
202\subsection{Splitting the job up}
203
204Running \code{setup.py install} builds and installs all modules in one
Greg Ward14deaae2000-09-11 00:33:15 +0000205run. If you prefer to work incrementally---especially useful if you
206want to customize the build process, or if things are going wrong---you
207can use the setup script to do one thing at a time. This is
Greg Ward3e7b1332000-05-30 03:00:43 +0000208particularly helpful when the build and install will be done by
209different users---e.g., you might want to build a module distribution
210and hand it off to a system administrator for installation (or do it
211yourself, with super-user privileges).
Greg Ward6002ffc2000-04-09 20:54:50 +0000212
213For example, you can build everything in one step, and then install
214everything in a second step, by invoking the setup script twice:
215\begin{verbatim}
216python setup.py build
217python setup.py install
218\end{verbatim}
219(If you do this, you will notice that running the \command{install}
Greg Ward14deaae2000-09-11 00:33:15 +0000220command first runs the \command{build} command, which---in this
221case---quickly notices that it has nothing to do, since everything in
222the \file{build} directory is up-to-date.)
Greg Ward29576562000-03-18 15:11:50 +0000223
Greg Ward14deaae2000-09-11 00:33:15 +0000224You may not need this ability to break things down often if all you do
225is install modules downloaded off the 'net, but it's very handy for more
226advanced tasks. If you get into distributing your own Python modules
227and extensions, you'll run lots of individual Distutils commands on
228their own.
Greg Ward7c1e5f62000-03-10 01:56:58 +0000229
230
Greg Wardc392caa2000-04-11 02:00:26 +0000231\subsection{How building works}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000232
Greg Wardc392caa2000-04-11 02:00:26 +0000233As implied above, the \command{build} command is responsible for putting
234the files to install into a \emph{build directory}. By default, this is
235\file{build} under the distribution root; if you're excessively
236concerned with speed, or want to keep the source tree pristine, you can
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000237change the build directory with the \longprogramopt{build-base} option.
238For example:
Greg Wardc392caa2000-04-11 02:00:26 +0000239\begin{verbatim}
240python setup.py build --build-base=/tmp/pybuild/foo-1.0
241\end{verbatim}
242(Or you could do this permanently with a directive in your system or
243personal Distutils configuration file; see
Greg Warde78298a2000-04-28 17:12:24 +0000244section~\ref{config-files}.) Normally, this isn't necessary.
Greg Wardc392caa2000-04-11 02:00:26 +0000245
246The default layout for the build tree is as follows:
247\begin{verbatim}
248--- build/ --- lib/
249or
250--- build/ --- lib.<plat>/
251 temp.<plat>/
252\end{verbatim}
253where \code{<plat>} expands to a brief description of the current
254OS/hardware platform. The first form, with just a \file{lib} directory,
255is used for ``pure module distributions''---that is, module
256distributions that include only pure Python modules. If a module
257distribution contains any extensions (modules written in C/C++, or Java
258for JPython), then the second form, with two \code{<plat>} directories,
259is used. In that case, the \file{temp.\filevar{plat}} directory holds
260temporary files generated by the compile/link process that don't
261actually get installed. In either case, the \file{lib} (or
262\file{lib.\filevar{plat}}) directory contains all Python modules (pure
263Python and extensions) that will be installed.
264
265In the future, more directories will be added to handle Python scripts,
266documentation, binary executables, and whatever else is needed to handle
Greg Wardd5faa7e2000-04-12 01:42:19 +0000267the job of installing Python modules and applications.
Greg Wardc392caa2000-04-11 02:00:26 +0000268
269
270\subsection{How installation works}
271
272After the \command{build} command runs (whether you run it explicitly,
273or the \command{install} command does it for you), the work of the
274\command{install} command is relatively simple: all it has to do is copy
275everything under \file{build/lib} (or \file{build/lib.\filevar{plat}})
276to your chosen installation directory.
277
278If you don't choose an installation directory---i.e., if you just run
279\code{setup.py install}---then the \command{install} command installs to
280the standard location for third-party Python modules. This location
281varies by platform and by how you built/installed Python itself. On
282Unix and Mac OS, it also depends on whether the module distribution
283being installed is pure Python or contains extensions (``non-pure''):
Greg Wardd5faa7e2000-04-12 01:42:19 +0000284\begin{tableiv}{l|l|l|c}{textrm}%
285 {Platform}{Standard installation location}{Default value}{Notes}
286 \lineiv{Unix (pure)}
Fred Drake01df4532000-06-30 03:36:41 +0000287 {\filenq{\filevar{prefix}/lib/python2.0/site-packages}}
288 {\filenq{/usr/local/lib/python2.0/site-packages}}
Greg Ward502d2b42000-04-12 14:20:15 +0000289 {(1)}
Greg Wardd5faa7e2000-04-12 01:42:19 +0000290 \lineiv{Unix (non-pure)}
Fred Drake01df4532000-06-30 03:36:41 +0000291 {\filenq{\filevar{exec-prefix}/lib/python2.0/site-packages}}
292 {\filenq{/usr/local/lib/python2.0/site-packages}}
Greg Ward502d2b42000-04-12 14:20:15 +0000293 {(1)}
Greg Wardd5faa7e2000-04-12 01:42:19 +0000294 \lineiv{Windows}
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000295 {\filenq{\filevar{prefix}}}
Greg Ward4756e5f2000-04-19 22:40:12 +0000296 {\filenq{C:\textbackslash{}Python}}
Greg Ward502d2b42000-04-12 14:20:15 +0000297 {(2)}
Greg Wardd5faa7e2000-04-12 01:42:19 +0000298 \lineiv{Mac~OS (pure)}
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000299 {\filenq{\filevar{prefix}:Lib}}
Greg Wardd5faa7e2000-04-12 01:42:19 +0000300 {\filenq{Python:Lib} \XXX{???}}
301 {}
302 \lineiv{Mac~OS (non-pure)}
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000303 {\filevar{prefix}:Mac:PlugIns}
Greg Wardd5faa7e2000-04-12 01:42:19 +0000304 {\filenq{Python:Mac:PlugIns}\XXX{???}}
305 {}
306\end{tableiv}
307
308\noindent Notes:
309\begin{description}
Greg Ward502d2b42000-04-12 14:20:15 +0000310\item[(1)] Most Linux distributions include Python as a standard part of
311 the system, so \filevar{prefix} and \filevar{exec-prefix} are usually
312 both \file{/usr} on Linux. If you build Python yourself on Linux (or
313 any Unix-like system), the default \filevar{prefix} and
314 \filevar{exec-prefix} are \file{/usr/local}.
315\item[(2)] The default installation directory on Windows was
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000316 \file{C:\textbackslash{}Program Files\textbackslash{}Python} under
317 Python 1.6a1, 1.5.2, and earlier.
Greg Wardd5faa7e2000-04-12 01:42:19 +0000318\end{description}
319
Greg Wardc392caa2000-04-11 02:00:26 +0000320\filevar{prefix} and \filevar{exec-prefix} stand for the directories
321that Python is installed to, and where it finds its libraries at
322run-time. They are always the same under Windows and Mac~OS, and very
323often the same under Unix. You can find out what your Python
324installation uses for \filevar{prefix} and \filevar{exec-prefix} by
325running Python in interactive mode and typing a few simple commands.
326Under Unix, just type \code{python} at the shell prompt; under Windows,
Fred Drake01df4532000-06-30 03:36:41 +0000327run ``Python 2.0 (interpreter)'' \XXX{right?}; under Mac~OS, \XXX{???}.
328Once the interpreter is started, you type Python code at the
329\samp{>>> } prompt. For example, on my Linux system, I type the three
330Python statements shown below, and get the output as shown, to find
331out my \filevar{prefix} and \filevar{exec-prefix}:
332
Greg Wardc392caa2000-04-11 02:00:26 +0000333\begin{verbatim}
334Python 1.5.2 (#1, Apr 18 1999, 16:03:16) [GCC pgcc-2.91.60 19981201 (egcs-1.1.1 on linux2
335Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
336>>> import sys
337>>> sys.prefix
338'/usr'
339>>> sys.exec_prefix
340'/usr'
341\end{verbatim}
342
343If you don't want to install to the standard location, or if you don't
344have permission to write there, then you need to read about alternate
345installations in the next section.
346
347
348% This rather nasty macro is used to generate the tables that describe
349% each installation scheme. It's nasty because it takes two arguments
350% for each "slot" in an installation scheme, there will soon be more
351% than five of these slots, and TeX has a limit of 10 arguments to a
352% macro. Uh-oh.
353
Greg Ward29576562000-03-18 15:11:50 +0000354\newcommand{\installscheme}[8]
355 {\begin{tableiii}{lll}{textrm}
356 {Type of file}
357 {Installation Directory}
358 {Override option}
359 \lineiii{pure module distribution}
360 {\filevar{#1}\filenq{#2}}
Greg Warda021aca2000-04-19 22:34:11 +0000361 {\longprogramopt{install-purelib}}
Greg Ward29576562000-03-18 15:11:50 +0000362 \lineiii{non-pure module distribution}
363 {\filevar{#3}\filenq{#4}}
Greg Warda021aca2000-04-19 22:34:11 +0000364 {\longprogramopt{install-platlib}}
Greg Ward29576562000-03-18 15:11:50 +0000365 \lineiii{scripts}
366 {\filevar{#5}\filenq{#6}}
Greg Warda021aca2000-04-19 22:34:11 +0000367 {\longprogramopt{install-scripts}}
Greg Ward29576562000-03-18 15:11:50 +0000368 \lineiii{data}
369 {\filevar{#7}\filenq{#8}}
Greg Warda021aca2000-04-19 22:34:11 +0000370 {\longprogramopt{install-data}}
Greg Ward29576562000-03-18 15:11:50 +0000371 \end{tableiii}}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000372
Greg Ward29576562000-03-18 15:11:50 +0000373\section{Alternate Installation}
Greg Warde78298a2000-04-28 17:12:24 +0000374\label{alt-install}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000375
Greg Ward29576562000-03-18 15:11:50 +0000376Often, it is necessary or desirable to install modules to a location
377other than the standard location for third-party Python modules. For
378example, on a Unix system you might not have permission to write to the
379standard third-party module directory. Or you might wish to try out a
380module before making it a standard part of your local Python
381installation; this is especially true when upgrading a distribution
382already present: you want to make sure your existing base of scripts
383still works with the new version before actually upgrading.
384
385The Distutils \command{install} command is designed to make installing
386module distributions to an alternate location simple and painless. The
387basic idea is that you supply a base directory for the installation, and
388the \command{install} command picks a set of directories (called an
389\emph{installation scheme}) under this base directory in which to
390install files. The details differ across platforms, so read whichever
391of the following section applies to you.
392
393
394\subsection{Alternate installation: Unix (the home scheme)}
Greg Warde78298a2000-04-28 17:12:24 +0000395\label{alt-unix-prefix}
Greg Ward29576562000-03-18 15:11:50 +0000396
397Under Unix, there are two ways to perform an alternate installation.
398The ``prefix scheme'' is similar to how alternate installation works
Greg Wardc392caa2000-04-11 02:00:26 +0000399under Windows and Mac~OS, but is not necessarily the most useful way to
Greg Ward29576562000-03-18 15:11:50 +0000400maintain a personal Python library. Hence, we document the more
401convenient and commonly useful ``home scheme'' first.
402
Greg Wardc392caa2000-04-11 02:00:26 +0000403The idea behind the ``home scheme'' is that you build and maintain a
404personal stash of Python modules, probably under your home directory.
405Installing a new module distribution is as simple as
Greg Ward29576562000-03-18 15:11:50 +0000406\begin{verbatim}
407python setup.py install --home=<dir>
408\end{verbatim}
Greg Warda021aca2000-04-19 22:34:11 +0000409where you can supply any directory you like for the \longprogramopt{home}
Greg Ward4756e5f2000-04-19 22:40:12 +0000410option. Lazy typists can just type a tilde (\code{\textasciitilde}); the
Greg Wardc392caa2000-04-11 02:00:26 +0000411\command{install} command will expand this to your home directory:
412\begin{verbatim}
413python setup.py install --home=~
414\end{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000415
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000416The \longprogramopt{home} option defines the installation base
417directory. Files are installed to the following directories under the
418installation base as follows:
Greg Ward29576562000-03-18 15:11:50 +0000419\installscheme{home}{/lib/python}
420 {home}{/lib/python}
421 {home}{/bin}
422 {home}{/share}
423
424\subsection{Alternate installation: Unix (the prefix scheme)}
Greg Warde78298a2000-04-28 17:12:24 +0000425\label{alt-unix-home}
Greg Ward29576562000-03-18 15:11:50 +0000426
427The ``prefix scheme'' is useful when you wish to use one Python
428installation to perform the build/install (i.e., to run the setup
429script), but install modules into the third-party module directory of a
430different Python installation (or something that looks like a different
431Python installation). If this sounds a trifle unusual, it is---that's
432why the ``home scheme'' comes first. However, there are at least two
433known cases where the prefix scheme will be useful.
434
Greg Ward19c67f82000-06-24 01:33:16 +0000435First, consider that many Linux distributions put Python in \file{/usr},
Greg Ward29576562000-03-18 15:11:50 +0000436rather than the more traditional \file{/usr/local}. This is entirely
437appropriate, since in those cases Python is part of ``the system''
438rather than a local add-on. However, if you are installing Python
439modules from source, you probably want them to go in
440\file{/usr/local/lib/python1.\filevar{X}} rather than
441\file{/usr/lib/python1.\filevar{X}}. This can be done with
442\begin{verbatim}
443/usr/bin/python setup.py install --prefix=/usr/local
444\end{verbatim}
445
446Another possibility is a network filesystem where the name used to write
447to a remote directory is different from the name used to read it: for
448example, the Python interpreter accessed as \file{/usr/local/bin/python}
449might search for modules in \file{/usr/local/lib/python1.\filevar{X}},
450but those modules would have to be installed to, say,
451\file{/mnt/\filevar{@server}/export/lib/python1.\filevar{X}}. This
452could be done with
453\begin{verbatim}
454/usr/local/bin/python setup.py install --prefix=/mnt/@server/export
455\end{verbatim}
456
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000457In either case, the \longprogramopt{prefix} option defines the
458installation base, and the \longprogramopt{exec-prefix} option defines
459the platform-specific installation base, which is used for
460platform-specific files. (Currently, this just means non-pure module
461distributions, but could be expanded to C libraries, binary executables,
462etc.) If \longprogramopt{exec-prefix} is not supplied, it defaults to
463\longprogramopt{prefix}. Files are installed as follows:
Greg Ward29576562000-03-18 15:11:50 +0000464
465\installscheme{prefix}{/lib/python1.\filevar{X}/site-packages}
466 {exec-prefix}{/lib/python1.\filevar{X}/site-packages}
467 {prefix}{/bin}
468 {prefix}{/share}
469
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000470There is no requirement that \longprogramopt{prefix} or
471\longprogramopt{exec-prefix} actually point to an alternate Python
472installation; if the directories listed above do not already exist, they
473are created at installation time.
Greg Ward29576562000-03-18 15:11:50 +0000474
475Incidentally, the real reason the prefix scheme is important is simply
476that a standard Unix installation uses the prefix scheme, but with
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000477\longprogramopt{prefix} and \longprogramopt{exec-prefix} supplied by
478Python itself (as \code{sys.prefix} and \code{sys.exec\_prefix}). Thus,
479you might think you'll never use the prefix scheme, but every time you
480run \code{python setup.py install} without any other options, you're
481using it.
Greg Ward29576562000-03-18 15:11:50 +0000482
483Note that installing extensions to an alternate Python installation has
484no effect on how those extensions are built: in particular, the Python
485header files (\file{Python.h} and friends) installed with the Python
486interpreter used to run the setup script will be used in compiling
487extensions. It is your responsibility to ensure that the interpreter
488used to run extensions installed in this way is compatibile with the
Greg Wardc392caa2000-04-11 02:00:26 +0000489interpreter used to build them. The best way to do this is to ensure
490that the two interpreters are the same version of Python (possibly
491different builds, or possibly copies of the same build). (Of course, if
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000492your \longprogramopt{prefix} and \longprogramopt{exec-prefix} don't even
493point to an alternate Python installation, this is immaterial.)
Greg Ward29576562000-03-18 15:11:50 +0000494
495
496\subsection{Alternate installation: Windows}
Greg Warde78298a2000-04-28 17:12:24 +0000497\label{alt-windows}
Greg Ward29576562000-03-18 15:11:50 +0000498
499Since Windows has no conception of a user's home directory, and since
500the standard Python installation under Windows is simpler than that
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000501under Unix, there's no point in having separate \longprogramopt{prefix}
502and \longprogramopt{home} options. Just use the \longprogramopt{prefix}
503option to specify a base directory, e.g.
Greg Ward29576562000-03-18 15:11:50 +0000504\begin{verbatim}
Greg Ward8e14f052000-03-22 01:00:23 +0000505python setup.py install --prefix="\Temp\Python"
Greg Ward29576562000-03-18 15:11:50 +0000506\end{verbatim}
Greg Ward4756e5f2000-04-19 22:40:12 +0000507to install modules to the \file{\textbackslash{}Temp} directory on the current
Greg Ward29576562000-03-18 15:11:50 +0000508drive.
509
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000510The installation base is defined by the \longprogramopt{prefix} option;
511the \longprogramopt{exec-prefix} option is not supported under Windows.
512Files are installed as follows:
Greg Ward29576562000-03-18 15:11:50 +0000513\installscheme{prefix}{}
514 {prefix}{}
Greg Ward4756e5f2000-04-19 22:40:12 +0000515 {prefix}{\textbackslash{}Scripts}
516 {prefix}{\textbackslash{}Data}
Greg Ward29576562000-03-18 15:11:50 +0000517
518
Greg Wardc392caa2000-04-11 02:00:26 +0000519\subsection{Alternate installation: Mac~OS}
Greg Warde78298a2000-04-28 17:12:24 +0000520\label{alt-macos}
Greg Ward29576562000-03-18 15:11:50 +0000521
Greg Wardc392caa2000-04-11 02:00:26 +0000522Like Windows, Mac~OS has no notion of home directories (or even of
Greg Ward29576562000-03-18 15:11:50 +0000523users), and a fairly simple standard Python installation. Thus, only a
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000524\longprogramopt{prefix} option is needed. It defines the installation
525base, and files are installed under it as follows:
Greg Ward29576562000-03-18 15:11:50 +0000526
Greg Ward6002ffc2000-04-09 20:54:50 +0000527\XXX{how do MacPython users run the interpreter with command-line args?}
Greg Ward29576562000-03-18 15:11:50 +0000528
529\installscheme{prefix}{:Lib}
530 {prefix}{:Mac:PlugIns}
Greg Ward8e14f052000-03-22 01:00:23 +0000531 {prefix}{:Scripts}
532 {prefix}{:Data}
Greg Ward29576562000-03-18 15:11:50 +0000533
Greg Ward6002ffc2000-04-09 20:54:50 +0000534\XXX{Corran Webster says: ``Modules are found in either \file{:Lib} or
Greg Ward29576562000-03-18 15:11:50 +0000535\file{:Mac:Lib}, while extensions usually go in
536\file{:Mac:PlugIns}''---does this mean that non-pure distributions should
537be divided between \file{:Mac:PlugIns} and \file{:Mac:Lib}? If so, that
538changes the granularity at which we care about modules: instead of
539``modules from pure distributions'' and ``modules from non-pure
540distributions'', it becomes ``modules from pure distributions'',
541``Python modules from non-pure distributions'', and ``extensions from
Greg Ward6002ffc2000-04-09 20:54:50 +0000542non-pure distributions''. Is this necessary?!?}
Greg Ward29576562000-03-18 15:11:50 +0000543
544
545\section{Custom Installation}
Greg Warde78298a2000-04-28 17:12:24 +0000546\label{custom-install}
Greg Ward29576562000-03-18 15:11:50 +0000547
548Sometimes, the alternate installation schemes described in
Greg Warde78298a2000-04-28 17:12:24 +0000549section~\ref{alt-install} just don't do what you want. You might
Greg Ward29576562000-03-18 15:11:50 +0000550want to tweak just one or two directories while keeping everything under
551the same base directory, or you might want to completely redefine the
552installation scheme. In either case, you're creating a \emph{custom
553 installation scheme}.
554
555You probably noticed the column of ``override options'' in the tables
556describing the alternate installation schemes above. Those options are
557how you define a custom installation scheme. These override options can
558be relative, absolute, or explicitly defined in terms of one of the
559installation base directories. (There are two installation base
560directories, and they are normally the same---they only differ when you
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000561use the Unix ``prefix scheme'' and supply different
562\longprogramopt{prefix} and \longprogramopt{exec-prefix} options.)
Greg Ward29576562000-03-18 15:11:50 +0000563
564For example, say you're installing a module distribution to your home
565directory under Unix---but you want scripts to go in
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000566\file{\textasciitilde/scripts} rather than \file{\textasciitilde/bin}.
567As you might expect, you can override this directory with the
568\longprogramopt{install-scripts} option; in this case, it makes most
569sense to supply a relative path, which will be interpreted relative to
570the installation base directory (your home directory, in this case):
Greg Ward29576562000-03-18 15:11:50 +0000571\begin{verbatim}
Greg Ward19c67f82000-06-24 01:33:16 +0000572python setup.py install --home=~ --install-scripts=scripts
Greg Ward29576562000-03-18 15:11:50 +0000573\end{verbatim}
574
575Another Unix example: suppose your Python installation was built and
576installed with a prefix of \file{/usr/local/python}, so under a standard
577installation scripts will wind up in \file{/usr/local/python/bin}. If
578you want them in \file{/usr/local/bin} instead, you would supply this
Greg Warda021aca2000-04-19 22:34:11 +0000579absolute directory for the \longprogramopt{install-scripts} option:
Greg Ward29576562000-03-18 15:11:50 +0000580\begin{verbatim}
581python setup.py install --install-scripts=/usr/local/bin
582\end{verbatim}
583(This performs an installation using the ``prefix scheme,'' where the
584prefix is whatever your Python interpreter was installed with---
585\file{/usr/local/python} in this case.)
586
587If you maintain Python on Windows, you might want third-party modules to
588live in a subdirectory of \filevar{prefix}, rather than right in
589\filevar{prefix} itself. This is almost as easy as customizing the
590script installation directory---you just have to remember that there are
591two types of modules to worry about, pure modules and non-pure modules
592(i.e., modules from a non-pure distribution). For example:
593\begin{verbatim}
594python setup.py install --install-purelib=Site --install-platlib=Site
595\end{verbatim}
596The specified installation directories are relative to \filevar{prefix}.
597Of course, you also have to ensure that these directories are in
598Python's module search path, e.g. by putting a \file{.pth} file in
Greg Ward6002ffc2000-04-09 20:54:50 +0000599\filevar{prefix} (\XXX{should have a section describing .pth files and
600 cross-ref it here}).
Greg Ward29576562000-03-18 15:11:50 +0000601
602If you want to define an entire installation scheme, you just have to
603supply all of the installation directory options. The recommended way
Greg Wardc392caa2000-04-11 02:00:26 +0000604to do this is to supply relative paths; for example, if you want to
605maintain all Python module-related files under \file{python} in your
606home directory, and you want a separate directory for each platform that
607you use your home directory from, you might define the following
Greg Ward29576562000-03-18 15:11:50 +0000608installation scheme:
609\begin{verbatim}
Greg Wardc392caa2000-04-11 02:00:26 +0000610python setup.py install --home=~ \
Greg Ward29576562000-03-18 15:11:50 +0000611 --install-purelib=python/lib \
612 --install-platlib=python/lib.$PLAT \
613 --install-scripts=python/scripts
614 --install-data=python/data
615\end{verbatim}
616or, equivalently,
617\begin{verbatim}
618python setup.py install --home=~/python \
619 --install-purelib=lib \
Greg Ward19c67f82000-06-24 01:33:16 +0000620 --install-platlib='lib.$PLAT' \
Greg Ward29576562000-03-18 15:11:50 +0000621 --install-scripts=scripts
622 --install-data=data
623\end{verbatim}
624\code{\$PLAT} is not (necessarily) an environment variable---it will be
625expanded by the Distutils as it parses your command line options (just
626as it does when parsing your configuration file(s)).
627
628Obviously, specifying the entire installation scheme every time you
629install a new module distribution would be very tedious. Thus, you can
630put these options into your Distutils config file (see
Greg Warde78298a2000-04-28 17:12:24 +0000631section~\ref{config-files}):
Greg Ward169f91b2000-03-10 01:57:51 +0000632\begin{verbatim}
633[install]
Greg Ward29576562000-03-18 15:11:50 +0000634install-base=$HOME
635install-purelib=python/lib
636install-platlib=python/lib.$PLAT
637install-scripts=python/scripts
638install-data=python/data
Greg Ward169f91b2000-03-10 01:57:51 +0000639\end{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000640or, equivalently,
Greg Ward169f91b2000-03-10 01:57:51 +0000641\begin{verbatim}
642[install]
Greg Ward29576562000-03-18 15:11:50 +0000643install-base=$HOME/python
644install-purelib=lib
645install-platlib=lib.$PLAT
646install-scripts=scripts
647install-data=data
Greg Ward169f91b2000-03-10 01:57:51 +0000648\end{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000649Note that these two are \emph{not} equivalent if you supply a different
650installation base directory when you run the setup script. For example,
Greg Ward7c1e5f62000-03-10 01:56:58 +0000651\begin{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000652python setup.py --install-base=/tmp
Greg Ward7c1e5f62000-03-10 01:56:58 +0000653\end{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000654would install pure modules to \filevar{/tmp/python/lib} in the first
655case, and to \filevar{/tmp/lib} in the second case. (For the second
656case, you probably want to supply an installation base of
657\file{/tmp/python}.)
Greg Ward169f91b2000-03-10 01:57:51 +0000658
Greg Ward29576562000-03-18 15:11:50 +0000659You probably noticed the use of \code{\$HOME} and \code{\$PLAT} in the
660sample configuration file input. These are Distutils configuration
661variables, which bear a strong resemblance to environment variables. In
Greg Wardc392caa2000-04-11 02:00:26 +0000662fact, you can use environment variables in config files---on platforms
663that have such a notion---but the Distutils additionally define a few
664extra variables that may not be in your environment, such as
665\code{\$PLAT}. (And of course, you can only use the configuration
666variables supplied by the Distutils on systems that don't have
667environment variables, such as Mac~OS (\XXX{true?}).) See
Greg Warde78298a2000-04-28 17:12:24 +0000668section~\ref{config-files} for details.
Greg Ward7c1e5f62000-03-10 01:56:58 +0000669
Greg Wardc392caa2000-04-11 02:00:26 +0000670\XXX{need some Windows and Mac~OS examples---when would custom
Greg Ward6002ffc2000-04-09 20:54:50 +0000671 installation schemes be needed on those platforms?}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000672
Greg Ward7c1e5f62000-03-10 01:56:58 +0000673
Greg Ward6002ffc2000-04-09 20:54:50 +0000674\section{Distutils Configuration Files}
Greg Warde78298a2000-04-28 17:12:24 +0000675\label{config-files}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000676
Greg Ward6002ffc2000-04-09 20:54:50 +0000677
678\section{Pre-Distutils Conventions}
Greg Warde78298a2000-04-28 17:12:24 +0000679\label{pre-distutils}
Greg Ward6002ffc2000-04-09 20:54:50 +0000680
681
Greg Wardc392caa2000-04-11 02:00:26 +0000682\subsection{The Makefile.pre.in file}
Greg Warde78298a2000-04-28 17:12:24 +0000683\label{makefile-pre-in}
Greg Ward6002ffc2000-04-09 20:54:50 +0000684
685
686\subsection{Installing modules manually}
Greg Warde78298a2000-04-28 17:12:24 +0000687\label{manual-install}
Greg Ward6002ffc2000-04-09 20:54:50 +0000688
689
690
Greg Ward7c1e5f62000-03-10 01:56:58 +0000691\end{document}