|
21 | 21 | % Finally, it might be useful to include all the material from my "Care |
22 | 22 | % and Feeding of a Python Installation" talk in here somewhere. Yow! |
23 | 23 |
|
24 | | -% Hey wow, Guido didn't write this one either! |
25 | 24 | \author{Greg Ward} |
26 | 25 | \authoraddress{E-mail: \email{ [email protected]}} |
27 | 26 |
|
|
40 | 39 | \section{Introduction} |
41 | 40 | \label{sec:intro} |
42 | 41 |
|
43 | | -\subsection{The new way: Distutils} |
44 | | -\label{sec:new-way} |
| 42 | +Although Python's extensive standard library covers many programming |
| 43 | +needs, there often comes a time when you need to add some new |
| 44 | +functionality to your Python installation in the form of third-party |
| 45 | +modules. This might be necessary to support your own programming, or to |
| 46 | +support an application that you want to use and that happens to be |
| 47 | +written in Python. |
| 48 | + |
| 49 | +In the past, there has been little support for adding third-party |
| 50 | +modules to an existing Python installation. With the introduction of |
| 51 | +the Python Distribution Utilities (Distutils for short) in Python 1.6, |
| 52 | +this is starting to change. Not everything will change overnight, |
| 53 | +though, so while this document concentrates on installing module |
| 54 | +distributions that use the Distutils, we will also spend some time |
| 55 | +dealing with the old ways. |
| 56 | + |
| 57 | +This document is aimed primarily at the people who need to install |
| 58 | +third-party Python modules: end-users and system administrators who just |
| 59 | +need to get some Python application running, and existing Python |
| 60 | +programmers who want to add some new goodies to their toolbox. You |
| 61 | +don't need to know Python to read this document; there will be some |
| 62 | +brief forays into using Python's interactive mode to explore your |
| 63 | +installation, but that's it. If you're looking for information on how |
| 64 | +to distribute your own Python modules so that others may use them, see |
| 65 | +the ``Distributing Python Modules'' manual. |
| 66 | + |
| 67 | + |
| 68 | +\subsection{Best case: trivial installation} |
| 69 | +\label{sec:trivial-inst} |
| 70 | + |
| 71 | +In the best case, someone will have prepared a special version of the |
| 72 | +module distribution you want to install that is targeted specifically at |
| 73 | +your platform and is installed just like any other software on your |
| 74 | +platform. For example, the module developer might make an executable |
| 75 | +installer available for Windows users, an RPM package for users of |
| 76 | +RPM-based Linux systems (Red Hat, SuSE, Mandrake, and many others), a |
| 77 | +Debian package for users of Debian-based Linux systems (Debian proper, |
| 78 | +Caldera, Corel, etc.), and so forth. |
| 79 | + |
| 80 | +In that case, you would download the installer appropriate to your |
| 81 | +platform and do the usual thing with it: run it if it's an executable |
| 82 | +installer, \code{rpm -I} it if it's an RPM, etc. You don't need to run |
| 83 | +Python or a setup script, you don't need to compile anything---you might |
| 84 | +not even need to read any instructions (although it's always a good idea |
| 85 | +to do so anyways). |
| 86 | + |
| 87 | +Of course, things will not always be that easy. You might be interested |
| 88 | +in a module distribution that nobody has created an easy-to-use |
| 89 | +installer for use on your platform. In that case, you'll have to start |
| 90 | +with the source distribution released by the module's |
| 91 | +author/maintainer. Installing from a source distribution is not too |
| 92 | +hard, as long as the modules are packaged in the standard way. The bulk |
| 93 | +of this document is about building and installing modules that were |
| 94 | +packaged in the standard way. |
| 95 | + |
| 96 | + |
| 97 | +\subsection{The new standard: Distutils} |
| 98 | +\label{sec:new-standard} |
| 99 | + |
| 100 | +If you download a module source distribution, you can tell pretty |
| 101 | +quickly if was packaged and distributed in the standard way, i.e. using |
| 102 | +the Distutils. First, the distribution's name and version number will |
| 103 | +be featured prominently in the name of the downloaded archive, e.g. |
| 104 | +\file{foo-1.0.tar.gz} or \file{widget-0.9.7.zip}. Next, the archive |
| 105 | +will unpack into a similarly-named directory: \file{foo-1.0} or |
| 106 | +\file{widget-0.9.7}. Additionally, the distribution will contain a |
| 107 | +setup script \file{setup.py}, and a \file{README.txt} (or possibly |
| 108 | +\file{README}), which should explain that building and installing the |
| 109 | +module distribution is a simple matter of running |
| 110 | +\begin{verbatim} |
| 111 | +python setup.py install |
| 112 | +\end{verbatim} |
45 | 113 |
|
| 114 | +If all these things are true, then you already know how to build and |
| 115 | +install the modules you've just downloaded: run the command above. |
| 116 | +Unless you need to install things in a non-standard way or customize the |
| 117 | +build process, you don't really need this manual. Or rather, the above |
| 118 | +command is everything you need to get out of this manual. |
46 | 119 |
|
47 | | -\subsection{The old way (pure Python): whatever you feel like} |
48 | | -\label{sec:old-way-pure} |
49 | 120 |
|
| 121 | +\subsection{The old way: no standards} |
| 122 | +\label{sec:old-way} |
50 | 123 |
|
51 | | -\subsection{The old way (extensions, \UNIX{} only): Makefile.pre.in} |
52 | | -\label{sec:old-way-ext} |
| 124 | +Before the Distutils, there was no infrastructure to support installing |
| 125 | +third-party modules in a consistent, standardized way. Thus, it's not |
| 126 | +really possible to write a general manual for installing Python modules |
| 127 | +that don't use the Distutils; the only truly general statement that can |
| 128 | +be made is, ``Read the module's own documentation on installation.'' |
53 | 129 |
|
| 130 | +However, such documentation is often woefully inadequate, assuming that |
| 131 | +you are familiar with how the Python library is laid out and will |
| 132 | +somehow just know where to copy various files in order for Python to |
| 133 | +find them. Also, since there is only one way to lay out the Python |
| 134 | +library on a given platform, this manual is a good place to learn that |
| 135 | +layout. That way, if you do have to manually install an old, |
| 136 | +pre-Distutils module distribution, you won't be completely on your own. |
54 | 137 |
|
| 138 | +Additionally, while there has not previously been a standard |
| 139 | +installation mechanism, Python has had some standard machinery for |
| 140 | +building extensions on Unix since Python \XXX{version?}. This machinery |
| 141 | +(the \file{Makefile.pre.in} file) is superseded by the Distutils, but it |
| 142 | +will no doubt live on in older module distributions for a while. This |
| 143 | +\file{Makefile.pre.in} mechanism is documented in the ``Extending \& |
| 144 | +Embedding Python'' manual, but that manual is aimed at module |
| 145 | +developers---hence, we include documentation for builders/installers |
| 146 | +here. |
55 | 147 |
|
| 148 | +All of the pre-Distutils material is tucked away in |
| 149 | +section~\ref{sec:pre-distutils}. |
56 | 150 |
|
57 | 151 |
|
58 | 152 | \section{Standard Build and Install} |
59 | 153 | \label{sec:normal-install} |
60 | 154 |
|
| 155 | +As described in section~\ref{sec:new-standard}, building and installing |
| 156 | +a module distribution using the Distutils is usually one simple command: |
| 157 | +\begin{verbatim} |
| 158 | +python setup.py install |
| 159 | +\end{verbatim} |
| 160 | +On Unix, you'd run this command from a shell prompt; on Windows, you |
| 161 | +have to open a command prompt window and do it there; on Mac OS ... |
| 162 | +\XXX{what the heck do you do on Mac OS?}. |
| 163 | + |
| 164 | + |
| 165 | +\subsection{Platform variations} |
| 166 | + |
| 167 | +You should always run the setup command from the distribution root |
| 168 | +directory, i.e. the top-level subdirectory that the module source |
| 169 | +distribution unpacks into. For example, if you've just downloaded a |
| 170 | +module source distribution \file{foo-1.0.tar.gz} onto a Unix system, the |
| 171 | +normal thing to do is: |
| 172 | +\begin{verbatim} |
| 173 | +gunzip -c foo-1.0.tar.gz | tar xf - # unpacks into directory foo-1.0 |
| 174 | +cd foo-1.0 |
| 175 | +python setup.py install |
| 176 | +\end{verbatim} |
| 177 | + |
| 178 | +On Windows, you'd probably unpack the archive before opening the command |
| 179 | +prompt. If you downloaded the archive file to \file{C:\bslash{}Temp}, then |
| 180 | +it probably unpacked (depending on your software) into |
| 181 | +\file{C:\bslash{}Temp\bslash{}foo-1.0}; from the command prompt window, you would |
| 182 | +then run |
| 183 | +\begin{verbatim} |
| 184 | +cd c:\temp\foo-1.0 |
| 185 | +python setup.py install |
| 186 | +\end{verbatim} |
| 187 | + |
| 188 | +On Mac OS, ... \XXX{again, how do you run Python scripts on Mac OS?} |
| 189 | + |
| 190 | + |
| 191 | +\subsection{Splitting the job up} |
| 192 | + |
| 193 | +Running \code{setup.py install} builds and installs all modules in one |
| 194 | +fell swoop. If you prefer to work incrementally---especially useful if |
| 195 | +you want to customize the build process, or if things are going |
| 196 | +wrong---you can use the setup script to do one thing at a time. |
| 197 | + |
| 198 | +For example, you can build everything in one step, and then install |
| 199 | +everything in a second step, by invoking the setup script twice: |
| 200 | +\begin{verbatim} |
| 201 | +python setup.py build |
| 202 | +python setup.py install |
| 203 | +\end{verbatim} |
| 204 | +(If you do this, you will notice that running the \command{install} |
| 205 | +command first runs the \command{build} command, which will quickly |
| 206 | +notice that it has nothing to do, since everything in the \file{build} |
| 207 | +directory is up-to-date. |
61 | 208 |
|
62 | 209 | % This will cover: |
63 | 210 | % * setup.py install (the usual thing) |
@@ -254,22 +401,22 @@ \subsection{Alternate installation: Mac OS} |
254 | 401 | \option{prefix} option is needed. It defines the installation base, and |
255 | 402 | files are installed under it as follows: |
256 | 403 |
|
257 | | -XXX how do MacPython users run the interpreter with command-line args? |
| 404 | +\XXX{how do MacPython users run the interpreter with command-line args?} |
258 | 405 |
|
259 | 406 | \installscheme{prefix}{:Lib} |
260 | 407 | {prefix}{:Mac:PlugIns} |
261 | 408 | {prefix}{:Scripts} |
262 | 409 | {prefix}{:Data} |
263 | 410 |
|
264 | | -XXX Corran Webster says: ``Modules are found in either \file{:Lib} or |
| 411 | +\XXX{Corran Webster says: ``Modules are found in either \file{:Lib} or |
265 | 412 | \file{:Mac:Lib}, while extensions usually go in |
266 | 413 | \file{:Mac:PlugIns}''---does this mean that non-pure distributions should |
267 | 414 | be divided between \file{:Mac:PlugIns} and \file{:Mac:Lib}? If so, that |
268 | 415 | changes the granularity at which we care about modules: instead of |
269 | 416 | ``modules from pure distributions'' and ``modules from non-pure |
270 | 417 | distributions'', it becomes ``modules from pure distributions'', |
271 | 418 | ``Python modules from non-pure distributions'', and ``extensions from |
272 | | -non-pure distributions''. Is this necessary?!? |
| 419 | +non-pure distributions''. Is this necessary?!?} |
273 | 420 |
|
274 | 421 |
|
275 | 422 | \section{Custom Installation} |
@@ -326,8 +473,8 @@ \section{Custom Installation} |
326 | 473 | The specified installation directories are relative to \filevar{prefix}. |
327 | 474 | Of course, you also have to ensure that these directories are in |
328 | 475 | Python'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 |
330 | | -cross-ref it here). |
| 476 | +\filevar{prefix} (\XXX{should have a section describing .pth files and |
| 477 | + cross-ref it here}). |
331 | 478 |
|
332 | 479 | If you want to define an entire installation scheme, you just have to |
333 | 480 | supply all of the installation directory options. The recommended way |
@@ -394,14 +541,28 @@ \section{Custom Installation} |
394 | 541 | your environment, such as \code{\$PATH}. See |
395 | 542 | section~\ref{sec:config-files} for details. |
396 | 543 |
|
397 | | -XXX need some Windows and Mac OS examples---when would custom |
398 | | -installation schemes be needed on those platforms? |
| 544 | +\XXX{need some Windows and Mac OS examples---when would custom |
| 545 | + installation schemes be needed on those platforms?} |
399 | 546 |
|
400 | 547 |
|
401 | | - |
402 | | -\section{Configuration Files} |
| 548 | +\section{Distutils Configuration Files} |
403 | 549 | \label{sec:config-files} |
404 | 550 |
|
405 | 551 | \comingsoon |
406 | 552 |
|
| 553 | + |
| 554 | + |
| 555 | +\section{Pre-Distutils Conventions} |
| 556 | +\label{sec:pre-distutils} |
| 557 | + |
| 558 | + |
| 559 | +\subsection{The \protect\file{Makefile.pre.in} file} |
| 560 | +\label{sec:makefile-pre-in} |
| 561 | + |
| 562 | + |
| 563 | +\subsection{Installing modules manually} |
| 564 | +\label{sec:manual-install} |
| 565 | + |
| 566 | + |
| 567 | + |
407 | 568 | \end{document} |
0 commit comments