Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 1 | \documentclass{howto} |
| 2 | \usepackage{ltxmarkup} |
| 3 | \usepackage{times} |
Greg Ward | 7593eb3 | 2000-04-09 03:59:15 +0000 | [diff] [blame] | 4 | \usepackage{distutils} |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 5 | |
| 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 Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 24 | \author{Greg Ward} |
| 25 | \authoraddress{E-mail: \email{gward@python.net}} |
| 26 | |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 27 | |
| 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} |
| 40 | \label{sec:intro} |
| 41 | |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame^] | 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. |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 66 | |
| 67 | |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame^] | 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. |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 95 | |
| 96 | |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame^] | 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} |
| 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. |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 119 | |
| 120 | |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame^] | 121 | \subsection{The old way: no standards} |
| 122 | \label{sec:old-way} |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 123 | |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame^] | 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.'' |
| 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. |
| 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. |
| 147 | |
| 148 | All of the pre-Distutils material is tucked away in |
| 149 | section~\ref{sec:pre-distutils}. |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 150 | |
| 151 | |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 152 | \section{Standard Build and Install} |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 153 | \label{sec:normal-install} |
| 154 | |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame^] | 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. |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 208 | |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 209 | % This will cover: |
| 210 | % * setup.py install (the usual thing) |
| 211 | % * setup.py build (if you like doing things one-at-a-time) |
| 212 | % * setup.py build install (not necessary unless you need to supply |
| 213 | % build options--ref. next section) |
| 214 | % * where things are installed, on Unix and Windows (Mac...?) |
| 215 | % * simple custom install: "install --prefix=$HOME" |
| 216 | \comingsoon |
| 217 | |
| 218 | |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 219 | |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 220 | % takes eight args (four pairs): |
| 221 | % pure module distribution base + directory |
| 222 | % non-pure module distribution base + directory |
| 223 | % script base + directory |
| 224 | % data base + directory |
| 225 | % ...and will no doubt take more args in future! |
| 226 | \newcommand{\installscheme}[8] |
| 227 | {\begin{tableiii}{lll}{textrm} |
| 228 | {Type of file} |
| 229 | {Installation Directory} |
| 230 | {Override option} |
| 231 | \lineiii{pure module distribution} |
| 232 | {\filevar{#1}\filenq{#2}} |
| 233 | {\option{install-purelib}} |
| 234 | \lineiii{non-pure module distribution} |
| 235 | {\filevar{#3}\filenq{#4}} |
| 236 | {\option{install-platlib}} |
| 237 | \lineiii{scripts} |
| 238 | {\filevar{#5}\filenq{#6}} |
| 239 | {\option{install-scripts}} |
| 240 | \lineiii{data} |
| 241 | {\filevar{#7}\filenq{#8}} |
| 242 | {\option{install-data}} |
| 243 | \end{tableiii}} |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 244 | |
| 245 | |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 246 | |
| 247 | |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 248 | \section{Alternate Installation} |
| 249 | \label{sec:alt-install} |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 250 | |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 251 | Often, it is necessary or desirable to install modules to a location |
| 252 | other than the standard location for third-party Python modules. For |
| 253 | example, on a Unix system you might not have permission to write to the |
| 254 | standard third-party module directory. Or you might wish to try out a |
| 255 | module before making it a standard part of your local Python |
| 256 | installation; this is especially true when upgrading a distribution |
| 257 | already present: you want to make sure your existing base of scripts |
| 258 | still works with the new version before actually upgrading. |
| 259 | |
| 260 | The Distutils \command{install} command is designed to make installing |
| 261 | module distributions to an alternate location simple and painless. The |
| 262 | basic idea is that you supply a base directory for the installation, and |
| 263 | the \command{install} command picks a set of directories (called an |
| 264 | \emph{installation scheme}) under this base directory in which to |
| 265 | install files. The details differ across platforms, so read whichever |
| 266 | of the following section applies to you. |
| 267 | |
| 268 | |
| 269 | \subsection{Alternate installation: Unix (the home scheme)} |
| 270 | \label{sec:alt-unix-prefix} |
| 271 | |
| 272 | Under Unix, there are two ways to perform an alternate installation. |
| 273 | The ``prefix scheme'' is similar to how alternate installation works |
| 274 | under Windows and Mac OS, but is not necessarily the most useful way to |
| 275 | maintain a personal Python library. Hence, we document the more |
| 276 | convenient and commonly useful ``home scheme'' first. |
| 277 | |
| 278 | The idea behind the ``home scheme'' is that you are building and |
| 279 | maintaining a personal stash of Python modules, probably under your home |
| 280 | directory. Installing a new module distribution is as simple as |
Greg Ward | 169f91b | 2000-03-10 01:57:51 +0000 | [diff] [blame] | 281 | \begin{verbatim} |
Greg Ward | 8e14f05 | 2000-03-22 01:00:23 +0000 | [diff] [blame] | 282 | python setup.py install --home # arg, doesn't work (getopt) |
Greg Ward | 169f91b | 2000-03-10 01:57:51 +0000 | [diff] [blame] | 283 | \end{verbatim} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 284 | or |
| 285 | \begin{verbatim} |
| 286 | python setup.py install --home=<dir> |
| 287 | \end{verbatim} |
| 288 | where you can supply any directory you like for the \option{home} |
| 289 | option. If you don't supply a directory (as in the first example |
| 290 | above), the \command{install} command uses the \code{HOME} environment |
| 291 | variable (or your official home directory as supplied by the password |
| 292 | file, if \code{HOME} is not defined). |
| 293 | |
| 294 | The \option{home} option defines the installation base directory. Files |
| 295 | are installed to the following directories under the installation base |
| 296 | as follows: |
| 297 | \installscheme{home}{/lib/python} |
| 298 | {home}{/lib/python} |
| 299 | {home}{/bin} |
| 300 | {home}{/share} |
| 301 | |
| 302 | \subsection{Alternate installation: Unix (the prefix scheme)} |
| 303 | \label{sec:alt-unix-home} |
| 304 | |
| 305 | The ``prefix scheme'' is useful when you wish to use one Python |
| 306 | installation to perform the build/install (i.e., to run the setup |
| 307 | script), but install modules into the third-party module directory of a |
| 308 | different Python installation (or something that looks like a different |
| 309 | Python installation). If this sounds a trifle unusual, it is---that's |
| 310 | why the ``home scheme'' comes first. However, there are at least two |
| 311 | known cases where the prefix scheme will be useful. |
| 312 | |
| 313 | First, consider that many Linux distribution put Python in \file{/usr}, |
| 314 | rather than the more traditional \file{/usr/local}. This is entirely |
| 315 | appropriate, since in those cases Python is part of ``the system'' |
| 316 | rather than a local add-on. However, if you are installing Python |
| 317 | modules from source, you probably want them to go in |
| 318 | \file{/usr/local/lib/python1.\filevar{X}} rather than |
| 319 | \file{/usr/lib/python1.\filevar{X}}. This can be done with |
| 320 | \begin{verbatim} |
| 321 | /usr/bin/python setup.py install --prefix=/usr/local |
| 322 | \end{verbatim} |
| 323 | |
| 324 | Another possibility is a network filesystem where the name used to write |
| 325 | to a remote directory is different from the name used to read it: for |
| 326 | example, the Python interpreter accessed as \file{/usr/local/bin/python} |
| 327 | might search for modules in \file{/usr/local/lib/python1.\filevar{X}}, |
| 328 | but those modules would have to be installed to, say, |
| 329 | \file{/mnt/\filevar{@server}/export/lib/python1.\filevar{X}}. This |
| 330 | could be done with |
| 331 | \begin{verbatim} |
| 332 | /usr/local/bin/python setup.py install --prefix=/mnt/@server/export |
| 333 | \end{verbatim} |
| 334 | |
| 335 | In either case, the \option{prefix} option defines the installation |
| 336 | base, and the \option{exec-prefix} option defines the platform-specific |
| 337 | installation base, which is used for platform-specific files. |
| 338 | (Currently, this just means non-pure module distributions, but could be |
| 339 | expanded to C libraries, binary executables, etc.) If |
| 340 | \option{exec-prefix} is not supplied, it defaults to \option{prefix}. |
| 341 | Files are installed as follows: |
| 342 | |
| 343 | \installscheme{prefix}{/lib/python1.\filevar{X}/site-packages} |
| 344 | {exec-prefix}{/lib/python1.\filevar{X}/site-packages} |
| 345 | {prefix}{/bin} |
| 346 | {prefix}{/share} |
| 347 | |
| 348 | There is no requirement that \option{prefix} or \option{exec-prefix} |
| 349 | actually point to an alternate Python installation; if the directories |
| 350 | listed above do not already exist, they are created at installation |
| 351 | time. |
| 352 | |
| 353 | Incidentally, the real reason the prefix scheme is important is simply |
| 354 | that a standard Unix installation uses the prefix scheme, but with |
| 355 | \option{prefix} and \option{exec-prefix} supplied by Python itself (as |
| 356 | \code{sys.prefix} and \code{sys.exec\_prefix}). Thus, you might think |
| 357 | you'll never use the prefix scheme, but every time you run \code{python |
| 358 | setup.py install} without any other options, you're using it. |
| 359 | |
| 360 | Note that installing extensions to an alternate Python installation has |
| 361 | no effect on how those extensions are built: in particular, the Python |
| 362 | header files (\file{Python.h} and friends) installed with the Python |
| 363 | interpreter used to run the setup script will be used in compiling |
| 364 | extensions. It is your responsibility to ensure that the interpreter |
| 365 | used to run extensions installed in this way is compatibile with the |
| 366 | interpreter used to build them. The best way to ensure this is that the |
| 367 | two interpreters are the same version of Python (possibly different |
| 368 | builds, or possibly copies of the same build). (Of course, if your |
| 369 | \option{prefix} and \option{exec-prefix} don't even point to an |
| 370 | alternate Python installation, this is immaterial.) |
| 371 | |
| 372 | |
| 373 | \subsection{Alternate installation: Windows} |
| 374 | \label{sec:alt-windows} |
| 375 | |
| 376 | Since Windows has no conception of a user's home directory, and since |
| 377 | the standard Python installation under Windows is simpler than that |
| 378 | under Unix, there's no point in having separate \option{prefix} and |
| 379 | \option{home} options. Just use the \option{prefix} option to specify |
| 380 | a base directory, e.g. |
| 381 | \begin{verbatim} |
Greg Ward | 8e14f05 | 2000-03-22 01:00:23 +0000 | [diff] [blame] | 382 | python setup.py install --prefix="\Temp\Python" |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 383 | \end{verbatim} |
| 384 | to install modules to the \file{\bslash{}Temp} directory on the current |
| 385 | drive. |
| 386 | |
| 387 | The installation base is defined by the \option{prefix} option; the |
| 388 | \option{exec-prefix} option is not supported under Windows. Files are |
| 389 | installed as follows: |
| 390 | \installscheme{prefix}{} |
| 391 | {prefix}{} |
| 392 | {prefix}{\bslash{}Scripts} |
| 393 | {prefix}{\bslash{}Data} |
| 394 | |
| 395 | |
| 396 | \subsection{Alternate installation: Mac OS} |
| 397 | \label{sec:alt-macos} |
| 398 | |
| 399 | Like Windows, Mac OS has no notion of home directories (or even of |
| 400 | users), and a fairly simple standard Python installation. Thus, only a |
| 401 | \option{prefix} option is needed. It defines the installation base, and |
| 402 | files are installed under it as follows: |
| 403 | |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame^] | 404 | \XXX{how do MacPython users run the interpreter with command-line args?} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 405 | |
| 406 | \installscheme{prefix}{:Lib} |
| 407 | {prefix}{:Mac:PlugIns} |
Greg Ward | 8e14f05 | 2000-03-22 01:00:23 +0000 | [diff] [blame] | 408 | {prefix}{:Scripts} |
| 409 | {prefix}{:Data} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 410 | |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame^] | 411 | \XXX{Corran Webster says: ``Modules are found in either \file{:Lib} or |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 412 | \file{:Mac:Lib}, while extensions usually go in |
| 413 | \file{:Mac:PlugIns}''---does this mean that non-pure distributions should |
| 414 | be divided between \file{:Mac:PlugIns} and \file{:Mac:Lib}? If so, that |
| 415 | changes the granularity at which we care about modules: instead of |
| 416 | ``modules from pure distributions'' and ``modules from non-pure |
| 417 | distributions'', it becomes ``modules from pure distributions'', |
| 418 | ``Python modules from non-pure distributions'', and ``extensions from |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame^] | 419 | non-pure distributions''. Is this necessary?!?} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 420 | |
| 421 | |
| 422 | \section{Custom Installation} |
| 423 | \label{sec:custom-install} |
| 424 | |
| 425 | Sometimes, the alternate installation schemes described in |
| 426 | section~\ref{sec:alt-install} just don't do what you want. You might |
| 427 | want to tweak just one or two directories while keeping everything under |
| 428 | the same base directory, or you might want to completely redefine the |
| 429 | installation scheme. In either case, you're creating a \emph{custom |
| 430 | installation scheme}. |
| 431 | |
| 432 | You probably noticed the column of ``override options'' in the tables |
| 433 | describing the alternate installation schemes above. Those options are |
| 434 | how you define a custom installation scheme. These override options can |
| 435 | be relative, absolute, or explicitly defined in terms of one of the |
| 436 | installation base directories. (There are two installation base |
| 437 | directories, and they are normally the same---they only differ when you |
| 438 | use the Unix ``prefix scheme'' and supply different \option{prefix} and |
| 439 | \option{exec-prefix} options.) |
| 440 | |
| 441 | For example, say you're installing a module distribution to your home |
| 442 | directory under Unix---but you want scripts to go in |
| 443 | \file{\tilde/scripts} rather than \file{\tilde/bin}. As you might |
| 444 | expect, you can override this directory with the |
| 445 | \option{install-scripts} option; in this case, it makes most sense to |
| 446 | supply a relative path, which will be interpreted relative to the |
| 447 | installation base directory (your home directory, in this case): |
| 448 | \begin{verbatim} |
| 449 | python setup.py install --home --install-scripts=scripts |
| 450 | \end{verbatim} |
| 451 | |
| 452 | Another Unix example: suppose your Python installation was built and |
| 453 | installed with a prefix of \file{/usr/local/python}, so under a standard |
| 454 | installation scripts will wind up in \file{/usr/local/python/bin}. If |
| 455 | you want them in \file{/usr/local/bin} instead, you would supply this |
| 456 | absolute directory for the \option{install-scripts} option: |
| 457 | \begin{verbatim} |
| 458 | python setup.py install --install-scripts=/usr/local/bin |
| 459 | \end{verbatim} |
| 460 | (This performs an installation using the ``prefix scheme,'' where the |
| 461 | prefix is whatever your Python interpreter was installed with--- |
| 462 | \file{/usr/local/python} in this case.) |
| 463 | |
| 464 | If you maintain Python on Windows, you might want third-party modules to |
| 465 | live in a subdirectory of \filevar{prefix}, rather than right in |
| 466 | \filevar{prefix} itself. This is almost as easy as customizing the |
| 467 | script installation directory---you just have to remember that there are |
| 468 | two types of modules to worry about, pure modules and non-pure modules |
| 469 | (i.e., modules from a non-pure distribution). For example: |
| 470 | \begin{verbatim} |
| 471 | python setup.py install --install-purelib=Site --install-platlib=Site |
| 472 | \end{verbatim} |
| 473 | The specified installation directories are relative to \filevar{prefix}. |
| 474 | Of course, you also have to ensure that these directories are in |
| 475 | Python's module search path, e.g. by putting a \file{.pth} file in |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame^] | 476 | \filevar{prefix} (\XXX{should have a section describing .pth files and |
| 477 | cross-ref it here}). |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 478 | |
| 479 | If you want to define an entire installation scheme, you just have to |
| 480 | supply all of the installation directory options. The recommended way |
| 481 | to do this is to supply relative paths; for example, if want to maintain |
| 482 | all Python module-related files under \file{python} in your home |
| 483 | directory, and you want a separate directory for each platform that you |
| 484 | use your home directory from, you might define the following |
| 485 | installation scheme: |
| 486 | \begin{verbatim} |
| 487 | python setup.py install --home \ |
| 488 | --install-purelib=python/lib \ |
| 489 | --install-platlib=python/lib.$PLAT \ |
| 490 | --install-scripts=python/scripts |
| 491 | --install-data=python/data |
| 492 | \end{verbatim} |
| 493 | or, equivalently, |
| 494 | \begin{verbatim} |
| 495 | python setup.py install --home=~/python \ |
| 496 | --install-purelib=lib \ |
| 497 | --install-platlib=lib.$PLAT \ |
| 498 | --install-scripts=scripts |
| 499 | --install-data=data |
| 500 | \end{verbatim} |
| 501 | \code{\$PLAT} is not (necessarily) an environment variable---it will be |
| 502 | expanded by the Distutils as it parses your command line options (just |
| 503 | as it does when parsing your configuration file(s)). |
| 504 | |
| 505 | Obviously, specifying the entire installation scheme every time you |
| 506 | install a new module distribution would be very tedious. Thus, you can |
| 507 | put these options into your Distutils config file (see |
| 508 | section~\ref{sec:config-files}): |
Greg Ward | 169f91b | 2000-03-10 01:57:51 +0000 | [diff] [blame] | 509 | \begin{verbatim} |
| 510 | [install] |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 511 | install-base=$HOME |
| 512 | install-purelib=python/lib |
| 513 | install-platlib=python/lib.$PLAT |
| 514 | install-scripts=python/scripts |
| 515 | install-data=python/data |
Greg Ward | 169f91b | 2000-03-10 01:57:51 +0000 | [diff] [blame] | 516 | \end{verbatim} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 517 | or, equivalently, |
Greg Ward | 169f91b | 2000-03-10 01:57:51 +0000 | [diff] [blame] | 518 | \begin{verbatim} |
| 519 | [install] |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 520 | install-base=$HOME/python |
| 521 | install-purelib=lib |
| 522 | install-platlib=lib.$PLAT |
| 523 | install-scripts=scripts |
| 524 | install-data=data |
Greg Ward | 169f91b | 2000-03-10 01:57:51 +0000 | [diff] [blame] | 525 | \end{verbatim} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 526 | Note that these two are \emph{not} equivalent if you supply a different |
| 527 | installation base directory when you run the setup script. For example, |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 528 | \begin{verbatim} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 529 | python setup.py --install-base=/tmp |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 530 | \end{verbatim} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 531 | would install pure modules to \filevar{/tmp/python/lib} in the first |
| 532 | case, and to \filevar{/tmp/lib} in the second case. (For the second |
| 533 | case, you probably want to supply an installation base of |
| 534 | \file{/tmp/python}.) |
Greg Ward | 169f91b | 2000-03-10 01:57:51 +0000 | [diff] [blame] | 535 | |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 536 | You probably noticed the use of \code{\$HOME} and \code{\$PLAT} in the |
| 537 | sample configuration file input. These are Distutils configuration |
| 538 | variables, which bear a strong resemblance to environment variables. In |
| 539 | fact, you can use environment variables in config files, but the |
| 540 | Distutils additionally define a few extra variables that may not be in |
| 541 | your environment, such as \code{\$PATH}. See |
| 542 | section~\ref{sec:config-files} for details. |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 543 | |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame^] | 544 | \XXX{need some Windows and Mac OS examples---when would custom |
| 545 | installation schemes be needed on those platforms?} |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 546 | |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 547 | |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame^] | 548 | \section{Distutils Configuration Files} |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 549 | \label{sec:config-files} |
| 550 | |
| 551 | \comingsoon |
| 552 | |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame^] | 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 | |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 568 | \end{document} |