blob: caff68641bc14a3085e0986edc1846ca59af33d9 [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
24% Hey wow, Guido didn't write this one either!
25\author{Greg Ward}
26\authoraddress{E-mail: \email{gward@python.net}}
27
Greg Ward7c1e5f62000-03-10 01:56:58 +000028
29\begin{document}
30
31\maketitle
32
33%\begin{abstract}
34%\noindent
35%Abstract this!
36%\end{abstract}
37
38\tableofcontents
39
40\section{Introduction}
41\label{sec:intro}
42
Greg Ward7c1e5f62000-03-10 01:56:58 +000043\subsection{The new way: Distutils}
44\label{sec:new-way}
45
46
47\subsection{The old way (pure Python): whatever you feel like}
48\label{sec:old-way-pure}
49
50
51\subsection{The old way (extensions, \UNIX{} only): Makefile.pre.in}
52\label{sec:old-way-ext}
53
54
55
56
57
Greg Ward29576562000-03-18 15:11:50 +000058\section{Standard Build and Install}
Greg Ward7c1e5f62000-03-10 01:56:58 +000059\label{sec:normal-install}
60
Greg Ward29576562000-03-18 15:11:50 +000061
Greg Ward7c1e5f62000-03-10 01:56:58 +000062% This will cover:
63% * setup.py install (the usual thing)
64% * setup.py build (if you like doing things one-at-a-time)
65% * setup.py build install (not necessary unless you need to supply
66% build options--ref. next section)
67% * where things are installed, on Unix and Windows (Mac...?)
68% * simple custom install: "install --prefix=$HOME"
69\comingsoon
70
71
Greg Ward7c1e5f62000-03-10 01:56:58 +000072
Greg Ward29576562000-03-18 15:11:50 +000073% takes eight args (four pairs):
74% pure module distribution base + directory
75% non-pure module distribution base + directory
76% script base + directory
77% data base + directory
78% ...and will no doubt take more args in future!
79\newcommand{\installscheme}[8]
80 {\begin{tableiii}{lll}{textrm}
81 {Type of file}
82 {Installation Directory}
83 {Override option}
84 \lineiii{pure module distribution}
85 {\filevar{#1}\filenq{#2}}
86 {\option{install-purelib}}
87 \lineiii{non-pure module distribution}
88 {\filevar{#3}\filenq{#4}}
89 {\option{install-platlib}}
90 \lineiii{scripts}
91 {\filevar{#5}\filenq{#6}}
92 {\option{install-scripts}}
93 \lineiii{data}
94 {\filevar{#7}\filenq{#8}}
95 {\option{install-data}}
96 \end{tableiii}}
Greg Ward7c1e5f62000-03-10 01:56:58 +000097
98
Greg Ward7c1e5f62000-03-10 01:56:58 +000099
100
Greg Ward29576562000-03-18 15:11:50 +0000101\section{Alternate Installation}
102\label{sec:alt-install}
Greg Ward7c1e5f62000-03-10 01:56:58 +0000103
Greg Ward29576562000-03-18 15:11:50 +0000104Often, it is necessary or desirable to install modules to a location
105other than the standard location for third-party Python modules. For
106example, on a Unix system you might not have permission to write to the
107standard third-party module directory. Or you might wish to try out a
108module before making it a standard part of your local Python
109installation; this is especially true when upgrading a distribution
110already present: you want to make sure your existing base of scripts
111still works with the new version before actually upgrading.
112
113The Distutils \command{install} command is designed to make installing
114module distributions to an alternate location simple and painless. The
115basic idea is that you supply a base directory for the installation, and
116the \command{install} command picks a set of directories (called an
117\emph{installation scheme}) under this base directory in which to
118install files. The details differ across platforms, so read whichever
119of the following section applies to you.
120
121
122\subsection{Alternate installation: Unix (the home scheme)}
123\label{sec:alt-unix-prefix}
124
125Under Unix, there are two ways to perform an alternate installation.
126The ``prefix scheme'' is similar to how alternate installation works
127under Windows and Mac OS, but is not necessarily the most useful way to
128maintain a personal Python library. Hence, we document the more
129convenient and commonly useful ``home scheme'' first.
130
131The idea behind the ``home scheme'' is that you are building and
132maintaining a personal stash of Python modules, probably under your home
133directory. Installing a new module distribution is as simple as
Greg Ward169f91b2000-03-10 01:57:51 +0000134\begin{verbatim}
Greg Ward8e14f052000-03-22 01:00:23 +0000135python setup.py install --home # arg, doesn't work (getopt)
Greg Ward169f91b2000-03-10 01:57:51 +0000136\end{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000137or
138\begin{verbatim}
139python setup.py install --home=<dir>
140\end{verbatim}
141where you can supply any directory you like for the \option{home}
142option. If you don't supply a directory (as in the first example
143above), the \command{install} command uses the \code{HOME} environment
144variable (or your official home directory as supplied by the password
145file, if \code{HOME} is not defined).
146
147The \option{home} option defines the installation base directory. Files
148are installed to the following directories under the installation base
149as follows:
150\installscheme{home}{/lib/python}
151 {home}{/lib/python}
152 {home}{/bin}
153 {home}{/share}
154
155\subsection{Alternate installation: Unix (the prefix scheme)}
156\label{sec:alt-unix-home}
157
158The ``prefix scheme'' is useful when you wish to use one Python
159installation to perform the build/install (i.e., to run the setup
160script), but install modules into the third-party module directory of a
161different Python installation (or something that looks like a different
162Python installation). If this sounds a trifle unusual, it is---that's
163why the ``home scheme'' comes first. However, there are at least two
164known cases where the prefix scheme will be useful.
165
166First, consider that many Linux distribution put Python in \file{/usr},
167rather than the more traditional \file{/usr/local}. This is entirely
168appropriate, since in those cases Python is part of ``the system''
169rather than a local add-on. However, if you are installing Python
170modules from source, you probably want them to go in
171\file{/usr/local/lib/python1.\filevar{X}} rather than
172\file{/usr/lib/python1.\filevar{X}}. This can be done with
173\begin{verbatim}
174/usr/bin/python setup.py install --prefix=/usr/local
175\end{verbatim}
176
177Another possibility is a network filesystem where the name used to write
178to a remote directory is different from the name used to read it: for
179example, the Python interpreter accessed as \file{/usr/local/bin/python}
180might search for modules in \file{/usr/local/lib/python1.\filevar{X}},
181but those modules would have to be installed to, say,
182\file{/mnt/\filevar{@server}/export/lib/python1.\filevar{X}}. This
183could be done with
184\begin{verbatim}
185/usr/local/bin/python setup.py install --prefix=/mnt/@server/export
186\end{verbatim}
187
188In either case, the \option{prefix} option defines the installation
189base, and the \option{exec-prefix} option defines the platform-specific
190installation base, which is used for platform-specific files.
191(Currently, this just means non-pure module distributions, but could be
192expanded to C libraries, binary executables, etc.) If
193\option{exec-prefix} is not supplied, it defaults to \option{prefix}.
194Files are installed as follows:
195
196\installscheme{prefix}{/lib/python1.\filevar{X}/site-packages}
197 {exec-prefix}{/lib/python1.\filevar{X}/site-packages}
198 {prefix}{/bin}
199 {prefix}{/share}
200
201There is no requirement that \option{prefix} or \option{exec-prefix}
202actually point to an alternate Python installation; if the directories
203listed above do not already exist, they are created at installation
204time.
205
206Incidentally, the real reason the prefix scheme is important is simply
207that a standard Unix installation uses the prefix scheme, but with
208\option{prefix} and \option{exec-prefix} supplied by Python itself (as
209\code{sys.prefix} and \code{sys.exec\_prefix}). Thus, you might think
210you'll never use the prefix scheme, but every time you run \code{python
211 setup.py install} without any other options, you're using it.
212
213Note that installing extensions to an alternate Python installation has
214no effect on how those extensions are built: in particular, the Python
215header files (\file{Python.h} and friends) installed with the Python
216interpreter used to run the setup script will be used in compiling
217extensions. It is your responsibility to ensure that the interpreter
218used to run extensions installed in this way is compatibile with the
219interpreter used to build them. The best way to ensure this is that the
220two interpreters are the same version of Python (possibly different
221builds, or possibly copies of the same build). (Of course, if your
222\option{prefix} and \option{exec-prefix} don't even point to an
223alternate Python installation, this is immaterial.)
224
225
226\subsection{Alternate installation: Windows}
227\label{sec:alt-windows}
228
229Since Windows has no conception of a user's home directory, and since
230the standard Python installation under Windows is simpler than that
231under Unix, there's no point in having separate \option{prefix} and
232\option{home} options. Just use the \option{prefix} option to specify
233a base directory, e.g.
234\begin{verbatim}
Greg Ward8e14f052000-03-22 01:00:23 +0000235python setup.py install --prefix="\Temp\Python"
Greg Ward29576562000-03-18 15:11:50 +0000236\end{verbatim}
237to install modules to the \file{\bslash{}Temp} directory on the current
238drive.
239
240The installation base is defined by the \option{prefix} option; the
241\option{exec-prefix} option is not supported under Windows. Files are
242installed as follows:
243\installscheme{prefix}{}
244 {prefix}{}
245 {prefix}{\bslash{}Scripts}
246 {prefix}{\bslash{}Data}
247
248
249\subsection{Alternate installation: Mac OS}
250\label{sec:alt-macos}
251
252Like Windows, Mac OS has no notion of home directories (or even of
253users), and a fairly simple standard Python installation. Thus, only a
254\option{prefix} option is needed. It defines the installation base, and
255files are installed under it as follows:
256
257XXX how do MacPython users run the interpreter with command-line args?
258
259\installscheme{prefix}{:Lib}
260 {prefix}{:Mac:PlugIns}
Greg Ward8e14f052000-03-22 01:00:23 +0000261 {prefix}{:Scripts}
262 {prefix}{:Data}
Greg Ward29576562000-03-18 15:11:50 +0000263
264XXX Corran Webster says: ``Modules are found in either \file{:Lib} or
265\file{:Mac:Lib}, while extensions usually go in
266\file{:Mac:PlugIns}''---does this mean that non-pure distributions should
267be divided between \file{:Mac:PlugIns} and \file{:Mac:Lib}? If so, that
268changes the granularity at which we care about modules: instead of
269``modules from pure distributions'' and ``modules from non-pure
270distributions'', it becomes ``modules from pure distributions'',
271``Python modules from non-pure distributions'', and ``extensions from
272non-pure distributions''. Is this necessary?!?
273
274
275\section{Custom Installation}
276\label{sec:custom-install}
277
278Sometimes, the alternate installation schemes described in
279section~\ref{sec:alt-install} just don't do what you want. You might
280want to tweak just one or two directories while keeping everything under
281the same base directory, or you might want to completely redefine the
282installation scheme. In either case, you're creating a \emph{custom
283 installation scheme}.
284
285You probably noticed the column of ``override options'' in the tables
286describing the alternate installation schemes above. Those options are
287how you define a custom installation scheme. These override options can
288be relative, absolute, or explicitly defined in terms of one of the
289installation base directories. (There are two installation base
290directories, and they are normally the same---they only differ when you
291use the Unix ``prefix scheme'' and supply different \option{prefix} and
292\option{exec-prefix} options.)
293
294For example, say you're installing a module distribution to your home
295directory under Unix---but you want scripts to go in
296\file{\tilde/scripts} rather than \file{\tilde/bin}. As you might
297expect, you can override this directory with the
298\option{install-scripts} option; in this case, it makes most sense to
299supply a relative path, which will be interpreted relative to the
300installation base directory (your home directory, in this case):
301\begin{verbatim}
302python setup.py install --home --install-scripts=scripts
303\end{verbatim}
304
305Another Unix example: suppose your Python installation was built and
306installed with a prefix of \file{/usr/local/python}, so under a standard
307installation scripts will wind up in \file{/usr/local/python/bin}. If
308you want them in \file{/usr/local/bin} instead, you would supply this
309absolute directory for the \option{install-scripts} option:
310\begin{verbatim}
311python setup.py install --install-scripts=/usr/local/bin
312\end{verbatim}
313(This performs an installation using the ``prefix scheme,'' where the
314prefix is whatever your Python interpreter was installed with---
315\file{/usr/local/python} in this case.)
316
317If you maintain Python on Windows, you might want third-party modules to
318live in a subdirectory of \filevar{prefix}, rather than right in
319\filevar{prefix} itself. This is almost as easy as customizing the
320script installation directory---you just have to remember that there are
321two types of modules to worry about, pure modules and non-pure modules
322(i.e., modules from a non-pure distribution). For example:
323\begin{verbatim}
324python setup.py install --install-purelib=Site --install-platlib=Site
325\end{verbatim}
326The specified installation directories are relative to \filevar{prefix}.
327Of course, you also have to ensure that these directories are in
328Python's module search path, e.g. by putting a \file{.pth} file in
329\filevar{prefix} (XXX should have a section describing .pth files and
330cross-ref it here).
331
332If you want to define an entire installation scheme, you just have to
333supply all of the installation directory options. The recommended way
334to do this is to supply relative paths; for example, if want to maintain
335all Python module-related files under \file{python} in your home
336directory, and you want a separate directory for each platform that you
337use your home directory from, you might define the following
338installation scheme:
339\begin{verbatim}
340python setup.py install --home \
341 --install-purelib=python/lib \
342 --install-platlib=python/lib.$PLAT \
343 --install-scripts=python/scripts
344 --install-data=python/data
345\end{verbatim}
346or, equivalently,
347\begin{verbatim}
348python setup.py install --home=~/python \
349 --install-purelib=lib \
350 --install-platlib=lib.$PLAT \
351 --install-scripts=scripts
352 --install-data=data
353\end{verbatim}
354\code{\$PLAT} is not (necessarily) an environment variable---it will be
355expanded by the Distutils as it parses your command line options (just
356as it does when parsing your configuration file(s)).
357
358Obviously, specifying the entire installation scheme every time you
359install a new module distribution would be very tedious. Thus, you can
360put these options into your Distutils config file (see
361section~\ref{sec:config-files}):
Greg Ward169f91b2000-03-10 01:57:51 +0000362\begin{verbatim}
363[install]
Greg Ward29576562000-03-18 15:11:50 +0000364install-base=$HOME
365install-purelib=python/lib
366install-platlib=python/lib.$PLAT
367install-scripts=python/scripts
368install-data=python/data
Greg Ward169f91b2000-03-10 01:57:51 +0000369\end{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000370or, equivalently,
Greg Ward169f91b2000-03-10 01:57:51 +0000371\begin{verbatim}
372[install]
Greg Ward29576562000-03-18 15:11:50 +0000373install-base=$HOME/python
374install-purelib=lib
375install-platlib=lib.$PLAT
376install-scripts=scripts
377install-data=data
Greg Ward169f91b2000-03-10 01:57:51 +0000378\end{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000379Note that these two are \emph{not} equivalent if you supply a different
380installation base directory when you run the setup script. For example,
Greg Ward7c1e5f62000-03-10 01:56:58 +0000381\begin{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000382python setup.py --install-base=/tmp
Greg Ward7c1e5f62000-03-10 01:56:58 +0000383\end{verbatim}
Greg Ward29576562000-03-18 15:11:50 +0000384would install pure modules to \filevar{/tmp/python/lib} in the first
385case, and to \filevar{/tmp/lib} in the second case. (For the second
386case, you probably want to supply an installation base of
387\file{/tmp/python}.)
Greg Ward169f91b2000-03-10 01:57:51 +0000388
Greg Ward29576562000-03-18 15:11:50 +0000389You probably noticed the use of \code{\$HOME} and \code{\$PLAT} in the
390sample configuration file input. These are Distutils configuration
391variables, which bear a strong resemblance to environment variables. In
392fact, you can use environment variables in config files, but the
393Distutils additionally define a few extra variables that may not be in
394your environment, such as \code{\$PATH}. See
395section~\ref{sec:config-files} for details.
Greg Ward7c1e5f62000-03-10 01:56:58 +0000396
Greg Ward29576562000-03-18 15:11:50 +0000397XXX need some Windows and Mac OS examples---when would custom
398installation schemes be needed on those platforms?
Greg Ward7c1e5f62000-03-10 01:56:58 +0000399
Greg Ward7c1e5f62000-03-10 01:56:58 +0000400
401
402\section{Configuration Files}
403\label{sec:config-files}
404
405\comingsoon
406
Greg Ward7c1e5f62000-03-10 01:56:58 +0000407\end{document}