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 | |
| 24 | % Hey wow, Guido didn't write this one either! |
| 25 | \author{Greg Ward} |
| 26 | \authoraddress{E-mail: \email{gward@python.net}} |
| 27 | |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 28 | |
| 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 Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 43 | \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 Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 58 | \section{Standard Build and Install} |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 59 | \label{sec:normal-install} |
| 60 | |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 61 | |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 62 | % 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 Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 72 | |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 73 | % 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 Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 97 | |
| 98 | |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 99 | |
| 100 | |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 101 | \section{Alternate Installation} |
| 102 | \label{sec:alt-install} |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 103 | |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 104 | Often, it is necessary or desirable to install modules to a location |
| 105 | other than the standard location for third-party Python modules. For |
| 106 | example, on a Unix system you might not have permission to write to the |
| 107 | standard third-party module directory. Or you might wish to try out a |
| 108 | module before making it a standard part of your local Python |
| 109 | installation; this is especially true when upgrading a distribution |
| 110 | already present: you want to make sure your existing base of scripts |
| 111 | still works with the new version before actually upgrading. |
| 112 | |
| 113 | The Distutils \command{install} command is designed to make installing |
| 114 | module distributions to an alternate location simple and painless. The |
| 115 | basic idea is that you supply a base directory for the installation, and |
| 116 | the \command{install} command picks a set of directories (called an |
| 117 | \emph{installation scheme}) under this base directory in which to |
| 118 | install files. The details differ across platforms, so read whichever |
| 119 | of the following section applies to you. |
| 120 | |
| 121 | |
| 122 | \subsection{Alternate installation: Unix (the home scheme)} |
| 123 | \label{sec:alt-unix-prefix} |
| 124 | |
| 125 | Under Unix, there are two ways to perform an alternate installation. |
| 126 | The ``prefix scheme'' is similar to how alternate installation works |
| 127 | under Windows and Mac OS, but is not necessarily the most useful way to |
| 128 | maintain a personal Python library. Hence, we document the more |
| 129 | convenient and commonly useful ``home scheme'' first. |
| 130 | |
| 131 | The idea behind the ``home scheme'' is that you are building and |
| 132 | maintaining a personal stash of Python modules, probably under your home |
| 133 | directory. Installing a new module distribution is as simple as |
Greg Ward | 169f91b | 2000-03-10 01:57:51 +0000 | [diff] [blame] | 134 | \begin{verbatim} |
Greg Ward | 8e14f05 | 2000-03-22 01:00:23 +0000 | [diff] [blame] | 135 | python setup.py install --home # arg, doesn't work (getopt) |
Greg Ward | 169f91b | 2000-03-10 01:57:51 +0000 | [diff] [blame] | 136 | \end{verbatim} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 137 | or |
| 138 | \begin{verbatim} |
| 139 | python setup.py install --home=<dir> |
| 140 | \end{verbatim} |
| 141 | where you can supply any directory you like for the \option{home} |
| 142 | option. If you don't supply a directory (as in the first example |
| 143 | above), the \command{install} command uses the \code{HOME} environment |
| 144 | variable (or your official home directory as supplied by the password |
| 145 | file, if \code{HOME} is not defined). |
| 146 | |
| 147 | The \option{home} option defines the installation base directory. Files |
| 148 | are installed to the following directories under the installation base |
| 149 | as 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 | |
| 158 | The ``prefix scheme'' is useful when you wish to use one Python |
| 159 | installation to perform the build/install (i.e., to run the setup |
| 160 | script), but install modules into the third-party module directory of a |
| 161 | different Python installation (or something that looks like a different |
| 162 | Python installation). If this sounds a trifle unusual, it is---that's |
| 163 | why the ``home scheme'' comes first. However, there are at least two |
| 164 | known cases where the prefix scheme will be useful. |
| 165 | |
| 166 | First, consider that many Linux distribution put Python in \file{/usr}, |
| 167 | rather than the more traditional \file{/usr/local}. This is entirely |
| 168 | appropriate, since in those cases Python is part of ``the system'' |
| 169 | rather than a local add-on. However, if you are installing Python |
| 170 | modules 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 | |
| 177 | Another possibility is a network filesystem where the name used to write |
| 178 | to a remote directory is different from the name used to read it: for |
| 179 | example, the Python interpreter accessed as \file{/usr/local/bin/python} |
| 180 | might search for modules in \file{/usr/local/lib/python1.\filevar{X}}, |
| 181 | but those modules would have to be installed to, say, |
| 182 | \file{/mnt/\filevar{@server}/export/lib/python1.\filevar{X}}. This |
| 183 | could be done with |
| 184 | \begin{verbatim} |
| 185 | /usr/local/bin/python setup.py install --prefix=/mnt/@server/export |
| 186 | \end{verbatim} |
| 187 | |
| 188 | In either case, the \option{prefix} option defines the installation |
| 189 | base, and the \option{exec-prefix} option defines the platform-specific |
| 190 | installation base, which is used for platform-specific files. |
| 191 | (Currently, this just means non-pure module distributions, but could be |
| 192 | expanded to C libraries, binary executables, etc.) If |
| 193 | \option{exec-prefix} is not supplied, it defaults to \option{prefix}. |
| 194 | Files 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 | |
| 201 | There is no requirement that \option{prefix} or \option{exec-prefix} |
| 202 | actually point to an alternate Python installation; if the directories |
| 203 | listed above do not already exist, they are created at installation |
| 204 | time. |
| 205 | |
| 206 | Incidentally, the real reason the prefix scheme is important is simply |
| 207 | that 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 |
| 210 | you'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 | |
| 213 | Note that installing extensions to an alternate Python installation has |
| 214 | no effect on how those extensions are built: in particular, the Python |
| 215 | header files (\file{Python.h} and friends) installed with the Python |
| 216 | interpreter used to run the setup script will be used in compiling |
| 217 | extensions. It is your responsibility to ensure that the interpreter |
| 218 | used to run extensions installed in this way is compatibile with the |
| 219 | interpreter used to build them. The best way to ensure this is that the |
| 220 | two interpreters are the same version of Python (possibly different |
| 221 | builds, or possibly copies of the same build). (Of course, if your |
| 222 | \option{prefix} and \option{exec-prefix} don't even point to an |
| 223 | alternate Python installation, this is immaterial.) |
| 224 | |
| 225 | |
| 226 | \subsection{Alternate installation: Windows} |
| 227 | \label{sec:alt-windows} |
| 228 | |
| 229 | Since Windows has no conception of a user's home directory, and since |
| 230 | the standard Python installation under Windows is simpler than that |
| 231 | under Unix, there's no point in having separate \option{prefix} and |
| 232 | \option{home} options. Just use the \option{prefix} option to specify |
| 233 | a base directory, e.g. |
| 234 | \begin{verbatim} |
Greg Ward | 8e14f05 | 2000-03-22 01:00:23 +0000 | [diff] [blame] | 235 | python setup.py install --prefix="\Temp\Python" |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 236 | \end{verbatim} |
| 237 | to install modules to the \file{\bslash{}Temp} directory on the current |
| 238 | drive. |
| 239 | |
| 240 | The installation base is defined by the \option{prefix} option; the |
| 241 | \option{exec-prefix} option is not supported under Windows. Files are |
| 242 | installed 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 | |
| 252 | Like Windows, Mac OS has no notion of home directories (or even of |
| 253 | users), and a fairly simple standard Python installation. Thus, only a |
| 254 | \option{prefix} option is needed. It defines the installation base, and |
| 255 | files are installed under it as follows: |
| 256 | |
| 257 | XXX how do MacPython users run the interpreter with command-line args? |
| 258 | |
| 259 | \installscheme{prefix}{:Lib} |
| 260 | {prefix}{:Mac:PlugIns} |
Greg Ward | 8e14f05 | 2000-03-22 01:00:23 +0000 | [diff] [blame] | 261 | {prefix}{:Scripts} |
| 262 | {prefix}{:Data} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 263 | |
| 264 | XXX 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 |
| 267 | be divided between \file{:Mac:PlugIns} and \file{:Mac:Lib}? If so, that |
| 268 | changes the granularity at which we care about modules: instead of |
| 269 | ``modules from pure distributions'' and ``modules from non-pure |
| 270 | distributions'', it becomes ``modules from pure distributions'', |
| 271 | ``Python modules from non-pure distributions'', and ``extensions from |
| 272 | non-pure distributions''. Is this necessary?!? |
| 273 | |
| 274 | |
| 275 | \section{Custom Installation} |
| 276 | \label{sec:custom-install} |
| 277 | |
| 278 | Sometimes, the alternate installation schemes described in |
| 279 | section~\ref{sec:alt-install} just don't do what you want. You might |
| 280 | want to tweak just one or two directories while keeping everything under |
| 281 | the same base directory, or you might want to completely redefine the |
| 282 | installation scheme. In either case, you're creating a \emph{custom |
| 283 | installation scheme}. |
| 284 | |
| 285 | You probably noticed the column of ``override options'' in the tables |
| 286 | describing the alternate installation schemes above. Those options are |
| 287 | how you define a custom installation scheme. These override options can |
| 288 | be relative, absolute, or explicitly defined in terms of one of the |
| 289 | installation base directories. (There are two installation base |
| 290 | directories, and they are normally the same---they only differ when you |
| 291 | use the Unix ``prefix scheme'' and supply different \option{prefix} and |
| 292 | \option{exec-prefix} options.) |
| 293 | |
| 294 | For example, say you're installing a module distribution to your home |
| 295 | directory under Unix---but you want scripts to go in |
| 296 | \file{\tilde/scripts} rather than \file{\tilde/bin}. As you might |
| 297 | expect, you can override this directory with the |
| 298 | \option{install-scripts} option; in this case, it makes most sense to |
| 299 | supply a relative path, which will be interpreted relative to the |
| 300 | installation base directory (your home directory, in this case): |
| 301 | \begin{verbatim} |
| 302 | python setup.py install --home --install-scripts=scripts |
| 303 | \end{verbatim} |
| 304 | |
| 305 | Another Unix example: suppose your Python installation was built and |
| 306 | installed with a prefix of \file{/usr/local/python}, so under a standard |
| 307 | installation scripts will wind up in \file{/usr/local/python/bin}. If |
| 308 | you want them in \file{/usr/local/bin} instead, you would supply this |
| 309 | absolute directory for the \option{install-scripts} option: |
| 310 | \begin{verbatim} |
| 311 | python setup.py install --install-scripts=/usr/local/bin |
| 312 | \end{verbatim} |
| 313 | (This performs an installation using the ``prefix scheme,'' where the |
| 314 | prefix is whatever your Python interpreter was installed with--- |
| 315 | \file{/usr/local/python} in this case.) |
| 316 | |
| 317 | If you maintain Python on Windows, you might want third-party modules to |
| 318 | live in a subdirectory of \filevar{prefix}, rather than right in |
| 319 | \filevar{prefix} itself. This is almost as easy as customizing the |
| 320 | script installation directory---you just have to remember that there are |
| 321 | two 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} |
| 324 | python setup.py install --install-purelib=Site --install-platlib=Site |
| 325 | \end{verbatim} |
| 326 | The specified installation directories are relative to \filevar{prefix}. |
| 327 | Of course, you also have to ensure that these directories are in |
| 328 | 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). |
| 331 | |
| 332 | If you want to define an entire installation scheme, you just have to |
| 333 | supply all of the installation directory options. The recommended way |
| 334 | to do this is to supply relative paths; for example, if want to maintain |
| 335 | all Python module-related files under \file{python} in your home |
| 336 | directory, and you want a separate directory for each platform that you |
| 337 | use your home directory from, you might define the following |
| 338 | installation scheme: |
| 339 | \begin{verbatim} |
| 340 | python 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} |
| 346 | or, equivalently, |
| 347 | \begin{verbatim} |
| 348 | python 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 |
| 355 | expanded by the Distutils as it parses your command line options (just |
| 356 | as it does when parsing your configuration file(s)). |
| 357 | |
| 358 | Obviously, specifying the entire installation scheme every time you |
| 359 | install a new module distribution would be very tedious. Thus, you can |
| 360 | put these options into your Distutils config file (see |
| 361 | section~\ref{sec:config-files}): |
Greg Ward | 169f91b | 2000-03-10 01:57:51 +0000 | [diff] [blame] | 362 | \begin{verbatim} |
| 363 | [install] |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 364 | install-base=$HOME |
| 365 | install-purelib=python/lib |
| 366 | install-platlib=python/lib.$PLAT |
| 367 | install-scripts=python/scripts |
| 368 | install-data=python/data |
Greg Ward | 169f91b | 2000-03-10 01:57:51 +0000 | [diff] [blame] | 369 | \end{verbatim} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 370 | or, equivalently, |
Greg Ward | 169f91b | 2000-03-10 01:57:51 +0000 | [diff] [blame] | 371 | \begin{verbatim} |
| 372 | [install] |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 373 | install-base=$HOME/python |
| 374 | install-purelib=lib |
| 375 | install-platlib=lib.$PLAT |
| 376 | install-scripts=scripts |
| 377 | install-data=data |
Greg Ward | 169f91b | 2000-03-10 01:57:51 +0000 | [diff] [blame] | 378 | \end{verbatim} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 379 | Note that these two are \emph{not} equivalent if you supply a different |
| 380 | installation base directory when you run the setup script. For example, |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 381 | \begin{verbatim} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 382 | python setup.py --install-base=/tmp |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 383 | \end{verbatim} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 384 | would install pure modules to \filevar{/tmp/python/lib} in the first |
| 385 | case, and to \filevar{/tmp/lib} in the second case. (For the second |
| 386 | case, you probably want to supply an installation base of |
| 387 | \file{/tmp/python}.) |
Greg Ward | 169f91b | 2000-03-10 01:57:51 +0000 | [diff] [blame] | 388 | |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 389 | You probably noticed the use of \code{\$HOME} and \code{\$PLAT} in the |
| 390 | sample configuration file input. These are Distutils configuration |
| 391 | variables, which bear a strong resemblance to environment variables. In |
| 392 | fact, you can use environment variables in config files, but the |
| 393 | Distutils additionally define a few extra variables that may not be in |
| 394 | your environment, such as \code{\$PATH}. See |
| 395 | section~\ref{sec:config-files} for details. |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 396 | |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 397 | XXX need some Windows and Mac OS examples---when would custom |
| 398 | installation schemes be needed on those platforms? |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 399 | |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 400 | |
| 401 | |
| 402 | \section{Configuration Files} |
| 403 | \label{sec:config-files} |
| 404 | |
| 405 | \comingsoon |
| 406 | |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 407 | \end{document} |