blob: c7da3dd9aa071f9a8903fb18157114f21c0eec41 [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}
Greg Warde78298a2000-04-28 17:12:24 +000040\label{intro}
Greg Ward7c1e5f62000-03-10 01:56:58 +000041
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}
Greg Warde78298a2000-04-28 17:12:24 +000069\label{trivial-inst}
Greg Ward6002ffc2000-04-09 20:54:50 +000070
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}
Greg Warde78298a2000-04-28 17:12:24 +000097\label{new-standard}
Greg Ward6002ffc2000-04-09 20:54:50 +000098
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}
Greg Warde78298a2000-04-28 17:12:24 +0000121\label{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
Greg Warde78298a2000-04-28 17:12:24 +0000150section~\ref{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 Warde78298a2000-04-28 17:12:24 +0000154\label{normal-install}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000155
Greg Warde78298a2000-04-28 17:12:24 +0000156As described in section~\ref{new-standard}, building and installing
Greg Ward6002ffc2000-04-09 20:54:50 +0000157a 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
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000171module source distribution \file{foo-1.0.tar.gz} onto a Unix system, the
Greg Ward6002ffc2000-04-09 20:54:50 +0000172normal 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
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000180prompt. If you downloaded the archive file to
181\file{C:\textbackslash{}Temp}, then it probably unpacked (depending on
182your software) into
183\file{C:\textbackslash{}Temp\textbackslash{}foo-1.0}; from the command
184prompt window, you would then run
Greg Ward6002ffc2000-04-09 20:54:50 +0000185\begin{verbatim}
186cd c:\temp\foo-1.0
187python setup.py install
188\end{verbatim}
189
Greg Wardc392caa2000-04-11 02:00:26 +0000190On Mac~OS, ... \XXX{again, how do you run Python scripts on Mac~OS?}
191
192\XXX{arg, my lovely ``bslash'' macro doesn't work in non-tt fonts! help
193 me \LaTeX, you're my only hope...}
Greg Ward6002ffc2000-04-09 20:54:50 +0000194
195
196\subsection{Splitting the job up}
197
198Running \code{setup.py install} builds and installs all modules in one
199fell swoop. If you prefer to work incrementally---especially useful if
200you want to customize the build process, or if things are going
Greg Ward3e7b1332000-05-30 03:00:43 +0000201wrong---you can use the setup script to do one thing at a time. This is
202particularly helpful when the build and install will be done by
203different users---e.g., you might want to build a module distribution
204and hand it off to a system administrator for installation (or do it
205yourself, with super-user privileges).
Greg Ward6002ffc2000-04-09 20:54:50 +0000206
207For example, you can build everything in one step, and then install
208everything in a second step, by invoking the setup script twice:
209\begin{verbatim}
210python setup.py build
211python setup.py install
212\end{verbatim}
213(If you do this, you will notice that running the \command{install}
Greg Wardc392caa2000-04-11 02:00:26 +0000214command first runs the \command{build} command, which quickly notices
215that it has nothing to do, since everything in the \file{build}
216directory is up-to-date.)
Greg Ward29576562000-03-18 15:11:50 +0000217
Greg Wardc392caa2000-04-11 02:00:26 +0000218\XXX{concrete reason for splitting things up?}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000219
220
Greg Wardc392caa2000-04-11 02:00:26 +0000221\subsection{How building works}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000222
Greg Wardc392caa2000-04-11 02:00:26 +0000223As implied above, the \command{build} command is responsible for putting
224the files to install into a \emph{build directory}. By default, this is
225\file{build} under the distribution root; if you're excessively
226concerned with speed, or want to keep the source tree pristine, you can
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000227change the build directory with the \longprogramopt{build-base} option.
228For example:
Greg Wardc392caa2000-04-11 02:00:26 +0000229\begin{verbatim}
230python setup.py build --build-base=/tmp/pybuild/foo-1.0
231\end{verbatim}
232(Or you could do this permanently with a directive in your system or
233personal Distutils configuration file; see
Greg Warde78298a2000-04-28 17:12:24 +0000234section~\ref{config-files}.) Normally, this isn't necessary.
Greg Wardc392caa2000-04-11 02:00:26 +0000235
236The default layout for the build tree is as follows:
237\begin{verbatim}
238--- build/ --- lib/
239or
240--- build/ --- lib.<plat>/
241 temp.<plat>/
242\end{verbatim}
243where \code{<plat>} expands to a brief description of the current
244OS/hardware platform. The first form, with just a \file{lib} directory,
245is used for ``pure module distributions''---that is, module
246distributions that include only pure Python modules. If a module
247distribution contains any extensions (modules written in C/C++, or Java
248for JPython), then the second form, with two \code{<plat>} directories,
249is used. In that case, the \file{temp.\filevar{plat}} directory holds
250temporary files generated by the compile/link process that don't
251actually get installed. In either case, the \file{lib} (or
252\file{lib.\filevar{plat}}) directory contains all Python modules (pure
253Python and extensions) that will be installed.
254
255In the future, more directories will be added to handle Python scripts,
256documentation, binary executables, and whatever else is needed to handle
Greg Wardd5faa7e2000-04-12 01:42:19 +0000257the job of installing Python modules and applications.
Greg Wardc392caa2000-04-11 02:00:26 +0000258
259
260\subsection{How installation works}
261
262After the \command{build} command runs (whether you run it explicitly,
263or the \command{install} command does it for you), the work of the
264\command{install} command is relatively simple: all it has to do is copy
265everything under \file{build/lib} (or \file{build/lib.\filevar{plat}})
266to your chosen installation directory.
267
268If you don't choose an installation directory---i.e., if you just run
269\code{setup.py install}---then the \command{install} command installs to
270the standard location for third-party Python modules. This location
271varies by platform and by how you built/installed Python itself. On
272Unix and Mac OS, it also depends on whether the module distribution
273being installed is pure Python or contains extensions (``non-pure''):
Greg Wardd5faa7e2000-04-12 01:42:19 +0000274\begin{tableiv}{l|l|l|c}{textrm}%
275 {Platform}{Standard installation location}{Default value}{Notes}
276 \lineiv{Unix (pure)}
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000277 {\filenq{\filevar{prefix}/lib/python1.6/site-packages}}
Greg Wardd5faa7e2000-04-12 01:42:19 +0000278 {\filenq{/usr/local/lib/python1.6/site-packages}}
Greg Ward502d2b42000-04-12 14:20:15 +0000279 {(1)}
Greg Wardd5faa7e2000-04-12 01:42:19 +0000280 \lineiv{Unix (non-pure)}
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000281 {\filenq{\filevar{exec-prefix}/lib/python1.6/site-packages}}
Greg Wardd5faa7e2000-04-12 01:42:19 +0000282 {\filenq{/usr/local/lib/python1.6/site-packages}}
Greg Ward502d2b42000-04-12 14:20:15 +0000283 {(1)}
Greg Wardd5faa7e2000-04-12 01:42:19 +0000284 \lineiv{Windows}
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000285 {\filenq{\filevar{prefix}}}
Greg Ward4756e5f2000-04-19 22:40:12 +0000286 {\filenq{C:\textbackslash{}Python}}
Greg Ward502d2b42000-04-12 14:20:15 +0000287 {(2)}
Greg Wardd5faa7e2000-04-12 01:42:19 +0000288 \lineiv{Mac~OS (pure)}
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000289 {\filenq{\filevar{prefix}:Lib}}
Greg Wardd5faa7e2000-04-12 01:42:19 +0000290 {\filenq{Python:Lib} \XXX{???}}
291 {}
292 \lineiv{Mac~OS (non-pure)}
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000293 {\filevar{prefix}:Mac:PlugIns}
Greg Wardd5faa7e2000-04-12 01:42:19 +0000294 {\filenq{Python:Mac:PlugIns}\XXX{???}}
295 {}
296\end{tableiv}
297
298\noindent Notes:
299\begin{description}
Greg Ward502d2b42000-04-12 14:20:15 +0000300\item[(1)] Most Linux distributions include Python as a standard part of
301 the system, so \filevar{prefix} and \filevar{exec-prefix} are usually
302 both \file{/usr} on Linux. If you build Python yourself on Linux (or
303 any Unix-like system), the default \filevar{prefix} and
304 \filevar{exec-prefix} are \file{/usr/local}.
305\item[(2)] The default installation directory on Windows was
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000306 \file{C:\textbackslash{}Program Files\textbackslash{}Python} under
307 Python 1.6a1, 1.5.2, and earlier.
Greg Wardd5faa7e2000-04-12 01:42:19 +0000308\end{description}
309
Greg Wardc392caa2000-04-11 02:00:26 +0000310\filevar{prefix} and \filevar{exec-prefix} stand for the directories
311that Python is installed to, and where it finds its libraries at
312run-time. They are always the same under Windows and Mac~OS, and very
313often the same under Unix. You can find out what your Python
314installation uses for \filevar{prefix} and \filevar{exec-prefix} by
315running Python in interactive mode and typing a few simple commands.
316Under Unix, just type \code{python} at the shell prompt; under Windows,
317run ``Python 1.6 (interpreter)'' \XXX{right?}; under Mac~OS, \XXX{???}.
318Once the interpreter is started, you type Python code at the \code{>>>}
319prompt. For example, on my Linux system, I type the three Python
320statements shown below, and get the output as shown, to find out my
321\filevar{prefix} and \filevar{exec-prefix}:
322\begin{verbatim}
323Python 1.5.2 (#1, Apr 18 1999, 16:03:16) [GCC pgcc-2.91.60 19981201 (egcs-1.1.1 on linux2
324Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
325>>> import sys
326>>> sys.prefix
327'/usr'
328>>> sys.exec_prefix
329'/usr'
330\end{verbatim}
331
332If you don't want to install to the standard location, or if you don't
333have permission to write there, then you need to read about alternate
334installations in the next section.
335
336
337% This rather nasty macro is used to generate the tables that describe
338% each installation scheme. It's nasty because it takes two arguments
339% for each "slot" in an installation scheme, there will soon be more
340% than five of these slots, and TeX has a limit of 10 arguments to a
341% macro. Uh-oh.
342
Greg Ward29576562000-03-18 15:11:50 +0000343\newcommand{\installscheme}[8]
344 {\begin{tableiii}{lll}{textrm}
345 {Type of file}
346 {Installation Directory}
347 {Override option}
348 \lineiii{pure module distribution}
349 {\filevar{#1}\filenq{#2}}
Greg Warda021aca2000-04-19 22:34:11 +0000350 {\longprogramopt{install-purelib}}
Greg Ward29576562000-03-18 15:11:50 +0000351 \lineiii{non-pure module distribution}
352 {\filevar{#3}\filenq{#4}}
Greg Warda021aca2000-04-19 22:34:11 +0000353 {\longprogramopt{install-platlib}}
Greg Ward29576562000-03-18 15:11:50 +0000354 \lineiii{scripts}
355 {\filevar{#5}\filenq{#6}}
Greg Warda021aca2000-04-19 22:34:11 +0000356 {\longprogramopt{install-scripts}}
Greg Ward29576562000-03-18 15:11:50 +0000357 \lineiii{data}
358 {\filevar{#7}\filenq{#8}}
Greg Warda021aca2000-04-19 22:34:11 +0000359 {\longprogramopt{install-data}}
Greg Ward29576562000-03-18 15:11:50 +0000360 \end{tableiii}}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000361
Greg Ward29576562000-03-18 15:11:50 +0000362\section{Alternate Installation}
Greg Warde78298a2000-04-28 17:12:24 +0000363\label{alt-install}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000364
Greg Ward29576562000-03-18 15:11:50 +0000365Often, it is necessary or desirable to install modules to a location
366other than the standard location for third-party Python modules. For
367example, on a Unix system you might not have permission to write to the
368standard third-party module directory. Or you might wish to try out a
369module before making it a standard part of your local Python
370installation; this is especially true when upgrading a distribution
371already present: you want to make sure your existing base of scripts
372still works with the new version before actually upgrading.
373
374The Distutils \command{install} command is designed to make installing
375module distributions to an alternate location simple and painless. The
376basic idea is that you supply a base directory for the installation, and
377the \command{install} command picks a set of directories (called an
378\emph{installation scheme}) under this base directory in which to
379install files. The details differ across platforms, so read whichever
380of the following section applies to you.
381
382
383\subsection{Alternate installation: Unix (the home scheme)}
Greg Warde78298a2000-04-28 17:12:24 +0000384\label{alt-unix-prefix}
Greg Ward29576562000-03-18 15:11:50 +0000385
386Under Unix, there are two ways to perform an alternate installation.
387The ``prefix scheme'' is similar to how alternate installation works
Greg Wardc392caa2000-04-11 02:00:26 +0000388under Windows and Mac~OS, but is not necessarily the most useful way to
Greg Ward29576562000-03-18 15:11:50 +0000389maintain a personal Python library. Hence, we document the more
390convenient and commonly useful ``home scheme'' first.
391
Greg Wardc392caa2000-04-11 02:00:26 +0000392The idea behind the ``home scheme'' is that you build and maintain a
393personal stash of Python modules, probably under your home directory.
394Installing a new module distribution is as simple as
Greg Ward29576562000-03-18 15:11:50 +0000395\begin{verbatim}
396python setup.py install --home=<dir>
397\end{verbatim}
Greg Warda021aca2000-04-19 22:34:11 +0000398where you can supply any directory you like for the \longprogramopt{home}
Greg Ward4756e5f2000-04-19 22:40:12 +0000399option. Lazy typists can just type a tilde (\code{\textasciitilde}); the
Greg Wardc392caa2000-04-11 02:00:26 +0000400\command{install} command will expand this to your home directory:
401\begin{verbatim}
402python setup.py install --home=~
403\end{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000404
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000405The \longprogramopt{home} option defines the installation base
406directory. Files are installed to the following directories under the
407installation base as follows:
Greg Ward29576562000-03-18 15:11:50 +0000408\installscheme{home}{/lib/python}
409 {home}{/lib/python}
410 {home}{/bin}
411 {home}{/share}
412
413\subsection{Alternate installation: Unix (the prefix scheme)}
Greg Warde78298a2000-04-28 17:12:24 +0000414\label{alt-unix-home}
Greg Ward29576562000-03-18 15:11:50 +0000415
416The ``prefix scheme'' is useful when you wish to use one Python
417installation to perform the build/install (i.e., to run the setup
418script), but install modules into the third-party module directory of a
419different Python installation (or something that looks like a different
420Python installation). If this sounds a trifle unusual, it is---that's
421why the ``home scheme'' comes first. However, there are at least two
422known cases where the prefix scheme will be useful.
423
424First, consider that many Linux distribution put Python in \file{/usr},
425rather than the more traditional \file{/usr/local}. This is entirely
426appropriate, since in those cases Python is part of ``the system''
427rather than a local add-on. However, if you are installing Python
428modules from source, you probably want them to go in
429\file{/usr/local/lib/python1.\filevar{X}} rather than
430\file{/usr/lib/python1.\filevar{X}}. This can be done with
431\begin{verbatim}
432/usr/bin/python setup.py install --prefix=/usr/local
433\end{verbatim}
434
435Another possibility is a network filesystem where the name used to write
436to a remote directory is different from the name used to read it: for
437example, the Python interpreter accessed as \file{/usr/local/bin/python}
438might search for modules in \file{/usr/local/lib/python1.\filevar{X}},
439but those modules would have to be installed to, say,
440\file{/mnt/\filevar{@server}/export/lib/python1.\filevar{X}}. This
441could be done with
442\begin{verbatim}
443/usr/local/bin/python setup.py install --prefix=/mnt/@server/export
444\end{verbatim}
445
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000446In either case, the \longprogramopt{prefix} option defines the
447installation base, and the \longprogramopt{exec-prefix} option defines
448the platform-specific installation base, which is used for
449platform-specific files. (Currently, this just means non-pure module
450distributions, but could be expanded to C libraries, binary executables,
451etc.) If \longprogramopt{exec-prefix} is not supplied, it defaults to
452\longprogramopt{prefix}. Files are installed as follows:
Greg Ward29576562000-03-18 15:11:50 +0000453
454\installscheme{prefix}{/lib/python1.\filevar{X}/site-packages}
455 {exec-prefix}{/lib/python1.\filevar{X}/site-packages}
456 {prefix}{/bin}
457 {prefix}{/share}
458
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000459There is no requirement that \longprogramopt{prefix} or
460\longprogramopt{exec-prefix} actually point to an alternate Python
461installation; if the directories listed above do not already exist, they
462are created at installation time.
Greg Ward29576562000-03-18 15:11:50 +0000463
464Incidentally, the real reason the prefix scheme is important is simply
465that a standard Unix installation uses the prefix scheme, but with
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000466\longprogramopt{prefix} and \longprogramopt{exec-prefix} supplied by
467Python itself (as \code{sys.prefix} and \code{sys.exec\_prefix}). Thus,
468you might think you'll never use the prefix scheme, but every time you
469run \code{python setup.py install} without any other options, you're
470using it.
Greg Ward29576562000-03-18 15:11:50 +0000471
472Note that installing extensions to an alternate Python installation has
473no effect on how those extensions are built: in particular, the Python
474header files (\file{Python.h} and friends) installed with the Python
475interpreter used to run the setup script will be used in compiling
476extensions. It is your responsibility to ensure that the interpreter
477used to run extensions installed in this way is compatibile with the
Greg Wardc392caa2000-04-11 02:00:26 +0000478interpreter used to build them. The best way to do this is to ensure
479that the two interpreters are the same version of Python (possibly
480different builds, or possibly copies of the same build). (Of course, if
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000481your \longprogramopt{prefix} and \longprogramopt{exec-prefix} don't even
482point to an alternate Python installation, this is immaterial.)
Greg Ward29576562000-03-18 15:11:50 +0000483
484
485\subsection{Alternate installation: Windows}
Greg Warde78298a2000-04-28 17:12:24 +0000486\label{alt-windows}
Greg Ward29576562000-03-18 15:11:50 +0000487
488Since Windows has no conception of a user's home directory, and since
489the standard Python installation under Windows is simpler than that
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000490under Unix, there's no point in having separate \longprogramopt{prefix}
491and \longprogramopt{home} options. Just use the \longprogramopt{prefix}
492option to specify a base directory, e.g.
Greg Ward29576562000-03-18 15:11:50 +0000493\begin{verbatim}
Greg Ward8e14f052000-03-22 01:00:23 +0000494python setup.py install --prefix="\Temp\Python"
Greg Ward29576562000-03-18 15:11:50 +0000495\end{verbatim}
Greg Ward4756e5f2000-04-19 22:40:12 +0000496to install modules to the \file{\textbackslash{}Temp} directory on the current
Greg Ward29576562000-03-18 15:11:50 +0000497drive.
498
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000499The installation base is defined by the \longprogramopt{prefix} option;
500the \longprogramopt{exec-prefix} option is not supported under Windows.
501Files are installed as follows:
Greg Ward29576562000-03-18 15:11:50 +0000502\installscheme{prefix}{}
503 {prefix}{}
Greg Ward4756e5f2000-04-19 22:40:12 +0000504 {prefix}{\textbackslash{}Scripts}
505 {prefix}{\textbackslash{}Data}
Greg Ward29576562000-03-18 15:11:50 +0000506
507
Greg Wardc392caa2000-04-11 02:00:26 +0000508\subsection{Alternate installation: Mac~OS}
Greg Warde78298a2000-04-28 17:12:24 +0000509\label{alt-macos}
Greg Ward29576562000-03-18 15:11:50 +0000510
Greg Wardc392caa2000-04-11 02:00:26 +0000511Like Windows, Mac~OS has no notion of home directories (or even of
Greg Ward29576562000-03-18 15:11:50 +0000512users), and a fairly simple standard Python installation. Thus, only a
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000513\longprogramopt{prefix} option is needed. It defines the installation
514base, and files are installed under it as follows:
Greg Ward29576562000-03-18 15:11:50 +0000515
Greg Ward6002ffc2000-04-09 20:54:50 +0000516\XXX{how do MacPython users run the interpreter with command-line args?}
Greg Ward29576562000-03-18 15:11:50 +0000517
518\installscheme{prefix}{:Lib}
519 {prefix}{:Mac:PlugIns}
Greg Ward8e14f052000-03-22 01:00:23 +0000520 {prefix}{:Scripts}
521 {prefix}{:Data}
Greg Ward29576562000-03-18 15:11:50 +0000522
Greg Ward6002ffc2000-04-09 20:54:50 +0000523\XXX{Corran Webster says: ``Modules are found in either \file{:Lib} or
Greg Ward29576562000-03-18 15:11:50 +0000524\file{:Mac:Lib}, while extensions usually go in
525\file{:Mac:PlugIns}''---does this mean that non-pure distributions should
526be divided between \file{:Mac:PlugIns} and \file{:Mac:Lib}? If so, that
527changes the granularity at which we care about modules: instead of
528``modules from pure distributions'' and ``modules from non-pure
529distributions'', it becomes ``modules from pure distributions'',
530``Python modules from non-pure distributions'', and ``extensions from
Greg Ward6002ffc2000-04-09 20:54:50 +0000531non-pure distributions''. Is this necessary?!?}
Greg Ward29576562000-03-18 15:11:50 +0000532
533
534\section{Custom Installation}
Greg Warde78298a2000-04-28 17:12:24 +0000535\label{custom-install}
Greg Ward29576562000-03-18 15:11:50 +0000536
537Sometimes, the alternate installation schemes described in
Greg Warde78298a2000-04-28 17:12:24 +0000538section~\ref{alt-install} just don't do what you want. You might
Greg Ward29576562000-03-18 15:11:50 +0000539want to tweak just one or two directories while keeping everything under
540the same base directory, or you might want to completely redefine the
541installation scheme. In either case, you're creating a \emph{custom
542 installation scheme}.
543
544You probably noticed the column of ``override options'' in the tables
545describing the alternate installation schemes above. Those options are
546how you define a custom installation scheme. These override options can
547be relative, absolute, or explicitly defined in terms of one of the
548installation base directories. (There are two installation base
549directories, and they are normally the same---they only differ when you
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000550use the Unix ``prefix scheme'' and supply different
551\longprogramopt{prefix} and \longprogramopt{exec-prefix} options.)
Greg Ward29576562000-03-18 15:11:50 +0000552
553For example, say you're installing a module distribution to your home
554directory under Unix---but you want scripts to go in
Greg Ward4eaa3bf2000-04-19 22:44:25 +0000555\file{\textasciitilde/scripts} rather than \file{\textasciitilde/bin}.
556As you might expect, you can override this directory with the
557\longprogramopt{install-scripts} option; in this case, it makes most
558sense to supply a relative path, which will be interpreted relative to
559the installation base directory (your home directory, in this case):
Greg Ward29576562000-03-18 15:11:50 +0000560\begin{verbatim}
561python setup.py install --home --install-scripts=scripts
562\end{verbatim}
563
564Another Unix example: suppose your Python installation was built and
565installed with a prefix of \file{/usr/local/python}, so under a standard
566installation scripts will wind up in \file{/usr/local/python/bin}. If
567you want them in \file{/usr/local/bin} instead, you would supply this
Greg Warda021aca2000-04-19 22:34:11 +0000568absolute directory for the \longprogramopt{install-scripts} option:
Greg Ward29576562000-03-18 15:11:50 +0000569\begin{verbatim}
570python setup.py install --install-scripts=/usr/local/bin
571\end{verbatim}
572(This performs an installation using the ``prefix scheme,'' where the
573prefix is whatever your Python interpreter was installed with---
574\file{/usr/local/python} in this case.)
575
576If you maintain Python on Windows, you might want third-party modules to
577live in a subdirectory of \filevar{prefix}, rather than right in
578\filevar{prefix} itself. This is almost as easy as customizing the
579script installation directory---you just have to remember that there are
580two types of modules to worry about, pure modules and non-pure modules
581(i.e., modules from a non-pure distribution). For example:
582\begin{verbatim}
583python setup.py install --install-purelib=Site --install-platlib=Site
584\end{verbatim}
585The specified installation directories are relative to \filevar{prefix}.
586Of course, you also have to ensure that these directories are in
587Python's module search path, e.g. by putting a \file{.pth} file in
Greg Ward6002ffc2000-04-09 20:54:50 +0000588\filevar{prefix} (\XXX{should have a section describing .pth files and
589 cross-ref it here}).
Greg Ward29576562000-03-18 15:11:50 +0000590
591If you want to define an entire installation scheme, you just have to
592supply all of the installation directory options. The recommended way
Greg Wardc392caa2000-04-11 02:00:26 +0000593to do this is to supply relative paths; for example, if you want to
594maintain all Python module-related files under \file{python} in your
595home directory, and you want a separate directory for each platform that
596you use your home directory from, you might define the following
Greg Ward29576562000-03-18 15:11:50 +0000597installation scheme:
598\begin{verbatim}
Greg Wardc392caa2000-04-11 02:00:26 +0000599python setup.py install --home=~ \
Greg Ward29576562000-03-18 15:11:50 +0000600 --install-purelib=python/lib \
601 --install-platlib=python/lib.$PLAT \
602 --install-scripts=python/scripts
603 --install-data=python/data
604\end{verbatim}
605or, equivalently,
606\begin{verbatim}
607python setup.py install --home=~/python \
608 --install-purelib=lib \
609 --install-platlib=lib.$PLAT \
610 --install-scripts=scripts
611 --install-data=data
612\end{verbatim}
613\code{\$PLAT} is not (necessarily) an environment variable---it will be
614expanded by the Distutils as it parses your command line options (just
615as it does when parsing your configuration file(s)).
616
617Obviously, specifying the entire installation scheme every time you
618install a new module distribution would be very tedious. Thus, you can
619put these options into your Distutils config file (see
Greg Warde78298a2000-04-28 17:12:24 +0000620section~\ref{config-files}):
Greg Ward169f91b2000-03-10 01:57:51 +0000621\begin{verbatim}
622[install]
Greg Ward29576562000-03-18 15:11:50 +0000623install-base=$HOME
624install-purelib=python/lib
625install-platlib=python/lib.$PLAT
626install-scripts=python/scripts
627install-data=python/data
Greg Ward169f91b2000-03-10 01:57:51 +0000628\end{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000629or, equivalently,
Greg Ward169f91b2000-03-10 01:57:51 +0000630\begin{verbatim}
631[install]
Greg Ward29576562000-03-18 15:11:50 +0000632install-base=$HOME/python
633install-purelib=lib
634install-platlib=lib.$PLAT
635install-scripts=scripts
636install-data=data
Greg Ward169f91b2000-03-10 01:57:51 +0000637\end{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000638Note that these two are \emph{not} equivalent if you supply a different
639installation base directory when you run the setup script. For example,
Greg Ward7c1e5f62000-03-10 01:56:58 +0000640\begin{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000641python setup.py --install-base=/tmp
Greg Ward7c1e5f62000-03-10 01:56:58 +0000642\end{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000643would install pure modules to \filevar{/tmp/python/lib} in the first
644case, and to \filevar{/tmp/lib} in the second case. (For the second
645case, you probably want to supply an installation base of
646\file{/tmp/python}.)
Greg Ward169f91b2000-03-10 01:57:51 +0000647
Greg Ward29576562000-03-18 15:11:50 +0000648You probably noticed the use of \code{\$HOME} and \code{\$PLAT} in the
649sample configuration file input. These are Distutils configuration
650variables, which bear a strong resemblance to environment variables. In
Greg Wardc392caa2000-04-11 02:00:26 +0000651fact, you can use environment variables in config files---on platforms
652that have such a notion---but the Distutils additionally define a few
653extra variables that may not be in your environment, such as
654\code{\$PLAT}. (And of course, you can only use the configuration
655variables supplied by the Distutils on systems that don't have
656environment variables, such as Mac~OS (\XXX{true?}).) See
Greg Warde78298a2000-04-28 17:12:24 +0000657section~\ref{config-files} for details.
Greg Ward7c1e5f62000-03-10 01:56:58 +0000658
Greg Wardc392caa2000-04-11 02:00:26 +0000659\XXX{need some Windows and Mac~OS examples---when would custom
Greg Ward6002ffc2000-04-09 20:54:50 +0000660 installation schemes be needed on those platforms?}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000661
Greg Ward7c1e5f62000-03-10 01:56:58 +0000662
Greg Ward6002ffc2000-04-09 20:54:50 +0000663\section{Distutils Configuration Files}
Greg Warde78298a2000-04-28 17:12:24 +0000664\label{config-files}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000665
Greg Wardc392caa2000-04-11 02:00:26 +0000666\XXX{not even implemented yet, much less documented!}
Greg Ward6002ffc2000-04-09 20:54:50 +0000667
668
669\section{Pre-Distutils Conventions}
Greg Warde78298a2000-04-28 17:12:24 +0000670\label{pre-distutils}
Greg Ward6002ffc2000-04-09 20:54:50 +0000671
672
Greg Wardc392caa2000-04-11 02:00:26 +0000673\subsection{The Makefile.pre.in file}
Greg Warde78298a2000-04-28 17:12:24 +0000674\label{makefile-pre-in}
Greg Ward6002ffc2000-04-09 20:54:50 +0000675
676
677\subsection{Installing modules manually}
Greg Warde78298a2000-04-28 17:12:24 +0000678\label{manual-install}
Greg Ward6002ffc2000-04-09 20:54:50 +0000679
680
681
Greg Ward7c1e5f62000-03-10 01:56:58 +0000682\end{document}