blob: c32fb06b1b82eb9936056202640327af3016e9f1 [file] [log] [blame]
Greg Ward7c1e5f62000-03-10 01:56:58 +00001\documentclass{howto}
2\usepackage{ltxmarkup}
3\usepackage{times}
4
5\title{Installing Python Modules}
6
7% The audience for this document includes people who don't know anything
8% about Python and aren't about to learn the language just in order to
9% install and maintain it for their users, i.e. system administrators.
10% Thus, I have to be sure to explain the basics at some point:
11% sys.path and PYTHONPATH at least. Should probably give pointers to
12% other docs on "import site", PYTHONSTARTUP, PYTHONHOME, etc.
13%
14% Also, I need to take into account that most modules out there don't
15% (yet) use Distutils: briefly explain the old Makefile.pre.in
16% convention (maybe move material from the E&E manual to here?), and
17% explain where to copy .py and .so files manually if the distribution
18% doesn't provide a mechanism for doing so.
19%
20% Finally, it might be useful to include all the material from my "Care
21% and Feeding of a Python Installation" talk in here somewhere. Yow!
22
23% Hey wow, Guido didn't write this one either!
24\author{Greg Ward}
25\authoraddress{E-mail: \email{gward@python.net}}
26
27% Should these be added to the standard Python doc tools? (They'll be
28% needed for my "Distributing Python Modules" guide, too.)
29\newcommand{\command}[1]{\code{#1}}
Greg Ward169f91b2000-03-10 01:57:51 +000030\newcommand{\option}[1]{\textsf{\small{#1}}}
Greg Ward7c1e5f62000-03-10 01:56:58 +000031\newcommand{\filevar}[1]{{\textsl{\filenq{#1}}}}
Greg Ward169f91b2000-03-10 01:57:51 +000032\newcommand{\homefile}[1]{\file{\tilde/#1}}
Greg Ward29576562000-03-18 15:11:50 +000033\newcommand{\comingsoon}{\emph{Coming soon...}}
Greg Ward7c1e5f62000-03-10 01:56:58 +000034
35% And how about these? Very handy for writing pathnames (tilde for
36% Unix, backslash for DOS/Windows).
37\renewcommand{\tilde}{\raisebox{-0.5ex}{\symbol{126}}}
Greg Ward29576562000-03-18 15:11:50 +000038\newcommand{\bslash}{\symbol{92}} % XXX only works in tt fonts!
Greg Ward7c1e5f62000-03-10 01:56:58 +000039
40
41\begin{document}
42
43\maketitle
44
45%\begin{abstract}
46%\noindent
47%Abstract this!
48%\end{abstract}
49
50\tableofcontents
51
52\section{Introduction}
53\label{sec:intro}
54
Greg Ward7c1e5f62000-03-10 01:56:58 +000055\subsection{The new way: Distutils}
56\label{sec:new-way}
57
58
59\subsection{The old way (pure Python): whatever you feel like}
60\label{sec:old-way-pure}
61
62
63\subsection{The old way (extensions, \UNIX{} only): Makefile.pre.in}
64\label{sec:old-way-ext}
65
66
67
68
69
Greg Ward29576562000-03-18 15:11:50 +000070\section{Standard Build and Install}
Greg Ward7c1e5f62000-03-10 01:56:58 +000071\label{sec:normal-install}
72
Greg Ward29576562000-03-18 15:11:50 +000073
Greg Ward7c1e5f62000-03-10 01:56:58 +000074% This will cover:
75% * setup.py install (the usual thing)
76% * setup.py build (if you like doing things one-at-a-time)
77% * setup.py build install (not necessary unless you need to supply
78% build options--ref. next section)
79% * where things are installed, on Unix and Windows (Mac...?)
80% * simple custom install: "install --prefix=$HOME"
81\comingsoon
82
83
Greg Ward7c1e5f62000-03-10 01:56:58 +000084
Greg Ward29576562000-03-18 15:11:50 +000085% takes eight args (four pairs):
86% pure module distribution base + directory
87% non-pure module distribution base + directory
88% script base + directory
89% data base + directory
90% ...and will no doubt take more args in future!
91\newcommand{\installscheme}[8]
92 {\begin{tableiii}{lll}{textrm}
93 {Type of file}
94 {Installation Directory}
95 {Override option}
96 \lineiii{pure module distribution}
97 {\filevar{#1}\filenq{#2}}
98 {\option{install-purelib}}
99 \lineiii{non-pure module distribution}
100 {\filevar{#3}\filenq{#4}}
101 {\option{install-platlib}}
102 \lineiii{scripts}
103 {\filevar{#5}\filenq{#6}}
104 {\option{install-scripts}}
105 \lineiii{data}
106 {\filevar{#7}\filenq{#8}}
107 {\option{install-data}}
108 \end{tableiii}}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000109
110
Greg Ward7c1e5f62000-03-10 01:56:58 +0000111
112
Greg Ward29576562000-03-18 15:11:50 +0000113\section{Alternate Installation}
114\label{sec:alt-install}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000115
Greg Ward29576562000-03-18 15:11:50 +0000116Often, it is necessary or desirable to install modules to a location
117other than the standard location for third-party Python modules. For
118example, on a Unix system you might not have permission to write to the
119standard third-party module directory. Or you might wish to try out a
120module before making it a standard part of your local Python
121installation; this is especially true when upgrading a distribution
122already present: you want to make sure your existing base of scripts
123still works with the new version before actually upgrading.
124
125The Distutils \command{install} command is designed to make installing
126module distributions to an alternate location simple and painless. The
127basic idea is that you supply a base directory for the installation, and
128the \command{install} command picks a set of directories (called an
129\emph{installation scheme}) under this base directory in which to
130install files. The details differ across platforms, so read whichever
131of the following section applies to you.
132
133
134\subsection{Alternate installation: Unix (the home scheme)}
135\label{sec:alt-unix-prefix}
136
137Under Unix, there are two ways to perform an alternate installation.
138The ``prefix scheme'' is similar to how alternate installation works
139under Windows and Mac OS, but is not necessarily the most useful way to
140maintain a personal Python library. Hence, we document the more
141convenient and commonly useful ``home scheme'' first.
142
143The idea behind the ``home scheme'' is that you are building and
144maintaining a personal stash of Python modules, probably under your home
145directory. Installing a new module distribution is as simple as
Greg Ward169f91b2000-03-10 01:57:51 +0000146\begin{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000147python setup.py install --home
Greg Ward169f91b2000-03-10 01:57:51 +0000148\end{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000149or
150\begin{verbatim}
151python setup.py install --home=<dir>
152\end{verbatim}
153where you can supply any directory you like for the \option{home}
154option. If you don't supply a directory (as in the first example
155above), the \command{install} command uses the \code{HOME} environment
156variable (or your official home directory as supplied by the password
157file, if \code{HOME} is not defined).
158
159The \option{home} option defines the installation base directory. Files
160are installed to the following directories under the installation base
161as follows:
162\installscheme{home}{/lib/python}
163 {home}{/lib/python}
164 {home}{/bin}
165 {home}{/share}
166
167\subsection{Alternate installation: Unix (the prefix scheme)}
168\label{sec:alt-unix-home}
169
170The ``prefix scheme'' is useful when you wish to use one Python
171installation to perform the build/install (i.e., to run the setup
172script), but install modules into the third-party module directory of a
173different Python installation (or something that looks like a different
174Python installation). If this sounds a trifle unusual, it is---that's
175why the ``home scheme'' comes first. However, there are at least two
176known cases where the prefix scheme will be useful.
177
178First, consider that many Linux distribution put Python in \file{/usr},
179rather than the more traditional \file{/usr/local}. This is entirely
180appropriate, since in those cases Python is part of ``the system''
181rather than a local add-on. However, if you are installing Python
182modules from source, you probably want them to go in
183\file{/usr/local/lib/python1.\filevar{X}} rather than
184\file{/usr/lib/python1.\filevar{X}}. This can be done with
185\begin{verbatim}
186/usr/bin/python setup.py install --prefix=/usr/local
187\end{verbatim}
188
189Another possibility is a network filesystem where the name used to write
190to a remote directory is different from the name used to read it: for
191example, the Python interpreter accessed as \file{/usr/local/bin/python}
192might search for modules in \file{/usr/local/lib/python1.\filevar{X}},
193but those modules would have to be installed to, say,
194\file{/mnt/\filevar{@server}/export/lib/python1.\filevar{X}}. This
195could be done with
196\begin{verbatim}
197/usr/local/bin/python setup.py install --prefix=/mnt/@server/export
198\end{verbatim}
199
200In either case, the \option{prefix} option defines the installation
201base, and the \option{exec-prefix} option defines the platform-specific
202installation base, which is used for platform-specific files.
203(Currently, this just means non-pure module distributions, but could be
204expanded to C libraries, binary executables, etc.) If
205\option{exec-prefix} is not supplied, it defaults to \option{prefix}.
206Files are installed as follows:
207
208\installscheme{prefix}{/lib/python1.\filevar{X}/site-packages}
209 {exec-prefix}{/lib/python1.\filevar{X}/site-packages}
210 {prefix}{/bin}
211 {prefix}{/share}
212
213There is no requirement that \option{prefix} or \option{exec-prefix}
214actually point to an alternate Python installation; if the directories
215listed above do not already exist, they are created at installation
216time.
217
218Incidentally, the real reason the prefix scheme is important is simply
219that a standard Unix installation uses the prefix scheme, but with
220\option{prefix} and \option{exec-prefix} supplied by Python itself (as
221\code{sys.prefix} and \code{sys.exec\_prefix}). Thus, you might think
222you'll never use the prefix scheme, but every time you run \code{python
223 setup.py install} without any other options, you're using it.
224
225Note that installing extensions to an alternate Python installation has
226no effect on how those extensions are built: in particular, the Python
227header files (\file{Python.h} and friends) installed with the Python
228interpreter used to run the setup script will be used in compiling
229extensions. It is your responsibility to ensure that the interpreter
230used to run extensions installed in this way is compatibile with the
231interpreter used to build them. The best way to ensure this is that the
232two interpreters are the same version of Python (possibly different
233builds, or possibly copies of the same build). (Of course, if your
234\option{prefix} and \option{exec-prefix} don't even point to an
235alternate Python installation, this is immaterial.)
236
237
238\subsection{Alternate installation: Windows}
239\label{sec:alt-windows}
240
241Since Windows has no conception of a user's home directory, and since
242the standard Python installation under Windows is simpler than that
243under Unix, there's no point in having separate \option{prefix} and
244\option{home} options. Just use the \option{prefix} option to specify
245a base directory, e.g.
246\begin{verbatim}
247python setup.py install --base="\Temp\Python"
248\end{verbatim}
249to install modules to the \file{\bslash{}Temp} directory on the current
250drive.
251
252The installation base is defined by the \option{prefix} option; the
253\option{exec-prefix} option is not supported under Windows. Files are
254installed as follows:
255\installscheme{prefix}{}
256 {prefix}{}
257 {prefix}{\bslash{}Scripts}
258 {prefix}{\bslash{}Data}
259
260
261\subsection{Alternate installation: Mac OS}
262\label{sec:alt-macos}
263
264Like Windows, Mac OS has no notion of home directories (or even of
265users), and a fairly simple standard Python installation. Thus, only a
266\option{prefix} option is needed. It defines the installation base, and
267files are installed under it as follows:
268
269XXX how do MacPython users run the interpreter with command-line args?
270
271\installscheme{prefix}{:Lib}
272 {prefix}{:Mac:PlugIns}
273 {prefix}{}
274 {prefix}{}
275
276XXX Corran Webster says: ``Modules are found in either \file{:Lib} or
277\file{:Mac:Lib}, while extensions usually go in
278\file{:Mac:PlugIns}''---does this mean that non-pure distributions should
279be divided between \file{:Mac:PlugIns} and \file{:Mac:Lib}? If so, that
280changes the granularity at which we care about modules: instead of
281``modules from pure distributions'' and ``modules from non-pure
282distributions'', it becomes ``modules from pure distributions'',
283``Python modules from non-pure distributions'', and ``extensions from
284non-pure distributions''. Is this necessary?!?
285
286
287\section{Custom Installation}
288\label{sec:custom-install}
289
290Sometimes, the alternate installation schemes described in
291section~\ref{sec:alt-install} just don't do what you want. You might
292want to tweak just one or two directories while keeping everything under
293the same base directory, or you might want to completely redefine the
294installation scheme. In either case, you're creating a \emph{custom
295 installation scheme}.
296
297You probably noticed the column of ``override options'' in the tables
298describing the alternate installation schemes above. Those options are
299how you define a custom installation scheme. These override options can
300be relative, absolute, or explicitly defined in terms of one of the
301installation base directories. (There are two installation base
302directories, and they are normally the same---they only differ when you
303use the Unix ``prefix scheme'' and supply different \option{prefix} and
304\option{exec-prefix} options.)
305
306For example, say you're installing a module distribution to your home
307directory under Unix---but you want scripts to go in
308\file{\tilde/scripts} rather than \file{\tilde/bin}. As you might
309expect, you can override this directory with the
310\option{install-scripts} option; in this case, it makes most sense to
311supply a relative path, which will be interpreted relative to the
312installation base directory (your home directory, in this case):
313\begin{verbatim}
314python setup.py install --home --install-scripts=scripts
315\end{verbatim}
316
317Another Unix example: suppose your Python installation was built and
318installed with a prefix of \file{/usr/local/python}, so under a standard
319installation scripts will wind up in \file{/usr/local/python/bin}. If
320you want them in \file{/usr/local/bin} instead, you would supply this
321absolute directory for the \option{install-scripts} option:
322\begin{verbatim}
323python setup.py install --install-scripts=/usr/local/bin
324\end{verbatim}
325(This performs an installation using the ``prefix scheme,'' where the
326prefix is whatever your Python interpreter was installed with---
327\file{/usr/local/python} in this case.)
328
329If you maintain Python on Windows, you might want third-party modules to
330live in a subdirectory of \filevar{prefix}, rather than right in
331\filevar{prefix} itself. This is almost as easy as customizing the
332script installation directory---you just have to remember that there are
333two types of modules to worry about, pure modules and non-pure modules
334(i.e., modules from a non-pure distribution). For example:
335\begin{verbatim}
336python setup.py install --install-purelib=Site --install-platlib=Site
337\end{verbatim}
338The specified installation directories are relative to \filevar{prefix}.
339Of course, you also have to ensure that these directories are in
340Python's module search path, e.g. by putting a \file{.pth} file in
341\filevar{prefix} (XXX should have a section describing .pth files and
342cross-ref it here).
343
344If you want to define an entire installation scheme, you just have to
345supply all of the installation directory options. The recommended way
346to do this is to supply relative paths; for example, if want to maintain
347all Python module-related files under \file{python} in your home
348directory, and you want a separate directory for each platform that you
349use your home directory from, you might define the following
350installation scheme:
351\begin{verbatim}
352python setup.py install --home \
353 --install-purelib=python/lib \
354 --install-platlib=python/lib.$PLAT \
355 --install-scripts=python/scripts
356 --install-data=python/data
357\end{verbatim}
358or, equivalently,
359\begin{verbatim}
360python setup.py install --home=~/python \
361 --install-purelib=lib \
362 --install-platlib=lib.$PLAT \
363 --install-scripts=scripts
364 --install-data=data
365\end{verbatim}
366\code{\$PLAT} is not (necessarily) an environment variable---it will be
367expanded by the Distutils as it parses your command line options (just
368as it does when parsing your configuration file(s)).
369
370Obviously, specifying the entire installation scheme every time you
371install a new module distribution would be very tedious. Thus, you can
372put these options into your Distutils config file (see
373section~\ref{sec:config-files}):
Greg Ward169f91b2000-03-10 01:57:51 +0000374\begin{verbatim}
375[install]
Greg Ward29576562000-03-18 15:11:50 +0000376install-base=$HOME
377install-purelib=python/lib
378install-platlib=python/lib.$PLAT
379install-scripts=python/scripts
380install-data=python/data
Greg Ward169f91b2000-03-10 01:57:51 +0000381\end{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000382or, equivalently,
Greg Ward169f91b2000-03-10 01:57:51 +0000383\begin{verbatim}
384[install]
Greg Ward29576562000-03-18 15:11:50 +0000385install-base=$HOME/python
386install-purelib=lib
387install-platlib=lib.$PLAT
388install-scripts=scripts
389install-data=data
Greg Ward169f91b2000-03-10 01:57:51 +0000390\end{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000391Note that these two are \emph{not} equivalent if you supply a different
392installation base directory when you run the setup script. For example,
Greg Ward7c1e5f62000-03-10 01:56:58 +0000393\begin{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000394python setup.py --install-base=/tmp
Greg Ward7c1e5f62000-03-10 01:56:58 +0000395\end{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000396would install pure modules to \filevar{/tmp/python/lib} in the first
397case, and to \filevar{/tmp/lib} in the second case. (For the second
398case, you probably want to supply an installation base of
399\file{/tmp/python}.)
Greg Ward169f91b2000-03-10 01:57:51 +0000400
Greg Ward29576562000-03-18 15:11:50 +0000401You probably noticed the use of \code{\$HOME} and \code{\$PLAT} in the
402sample configuration file input. These are Distutils configuration
403variables, which bear a strong resemblance to environment variables. In
404fact, you can use environment variables in config files, but the
405Distutils additionally define a few extra variables that may not be in
406your environment, such as \code{\$PATH}. See
407section~\ref{sec:config-files} for details.
Greg Ward7c1e5f62000-03-10 01:56:58 +0000408
Greg Ward29576562000-03-18 15:11:50 +0000409XXX need some Windows and Mac OS examples---when would custom
410installation schemes be needed on those platforms?
Greg Ward7c1e5f62000-03-10 01:56:58 +0000411
Greg Ward7c1e5f62000-03-10 01:56:58 +0000412
413
414\section{Configuration Files}
415\label{sec:config-files}
416
417\comingsoon
418
Greg Ward7c1e5f62000-03-10 01:56:58 +0000419\end{document}