Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame^] | 1 | \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}} |
| 30 | \newcommand{\option}[1]{\code{#1}} |
| 31 | \newcommand{\filevar}[1]{{\textsl{\filenq{#1}}}} |
| 32 | \newcommand{\comingsoon}{\emph{Coming soon$\ \ldots$}} |
| 33 | |
| 34 | % And how about these? Very handy for writing pathnames (tilde for |
| 35 | % Unix, backslash for DOS/Windows). |
| 36 | \renewcommand{\tilde}{\raisebox{-0.5ex}{\symbol{126}}} |
| 37 | \newcommand{\bslash}{\symbol{92}} |
| 38 | |
| 39 | |
| 40 | \begin{document} |
| 41 | |
| 42 | \maketitle |
| 43 | |
| 44 | %\begin{abstract} |
| 45 | %\noindent |
| 46 | %Abstract this! |
| 47 | %\end{abstract} |
| 48 | |
| 49 | \tableofcontents |
| 50 | |
| 51 | \section{Introduction} |
| 52 | \label{sec:intro} |
| 53 | |
| 54 | \comingsoon |
| 55 | |
| 56 | \subsection{The new way: Distutils} |
| 57 | \label{sec:new-way} |
| 58 | |
| 59 | |
| 60 | \subsection{The old way (pure Python): whatever you feel like} |
| 61 | \label{sec:old-way-pure} |
| 62 | |
| 63 | |
| 64 | \subsection{The old way (extensions, \UNIX{} only): Makefile.pre.in} |
| 65 | \label{sec:old-way-ext} |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | \section{Normal Build and Install} |
| 72 | \label{sec:normal-install} |
| 73 | |
| 74 | % 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 | |
| 84 | \section{Custom Extension Building} |
| 85 | \label{sec:custom-ext} |
| 86 | |
| 87 | % This will cover: |
| 88 | % * normal extension build -- stress that it doesn't matter, you |
| 89 | % do the same thing whether there are extensions or not |
| 90 | % * what you might want to customize: compiler and compiler |
| 91 | % flags (warn of the dangers); per-file compiler flags |
| 92 | % (not handled yet!) |
| 93 | % * when things go wrong: I don't know! (and I don't know what |
| 94 | % to do, either!) |
| 95 | \comingsoon |
| 96 | |
| 97 | |
| 98 | \section{Custom Installation (\UNIX)} |
| 99 | \label{sec:custom-install-unix} |
| 100 | |
| 101 | % XXX probably should banish mentions of Windows here to the |
| 102 | % separate "Non-standard installation (Windows)" section. |
| 103 | |
| 104 | A \dfn{custom installation} is where you install modules to a location |
| 105 | that's not in Python's default module search path. There are a couple |
| 106 | of reasons you might want to do this; the most typical is simply that |
| 107 | you don't have permission to write to the standard Python library |
| 108 | directory. Or, even if you do have write permission to the standard |
| 109 | library, you might wish to install a module distribution into a |
| 110 | non-standard place for testing or experimentation. (This is especially |
| 111 | useful when upgrading an existing module distribution: you might want to |
| 112 | make sure that your existing scripts continue to work as before, and |
| 113 | only then install the upgrade ``for real.'') |
| 114 | |
| 115 | (XXX terminology: I keep saying ``standard Python library directory'' |
| 116 | when I really mean ``the site-packages directory under the standard |
| 117 | Python library directory''. Is there a better way?) |
| 118 | |
| 119 | In any event, you can easily install to non-standard locations with a |
| 120 | couple of options to the \command{install} command: |
| 121 | |
| 122 | \begin{tableii}{ll}{option}{Option}{Description} |
| 123 | \lineii{prefix}{base dir for pure Python distributions |
| 124 | (overrides \code{sys.prefix})} |
| 125 | \lineii{exec-prefix}{base dir for distributions with extensions |
| 126 | (overrides \code{sys.exec_prefix})} |
| 127 | \lineii{install-lib}{install dir for top-level modules from pure |
| 128 | Python distributions} |
| 129 | \lineii{install-platlib}{install dir for top-level modules from |
| 130 | distributions with extensions} |
| 131 | \lineii{install-path}{extra path under \option{install-lib} or |
| 132 | \option{install-platlib} to install to} |
| 133 | \end{tableii} |
| 134 | |
| 135 | |
| 136 | \subsection{Prefix options} |
| 137 | \label{sec:prefix-options} |
| 138 | |
| 139 | There are a lot of picky little rules that govern the interactions of |
| 140 | these five options. As usual, it's easier to explain things with |
| 141 | examples, so we'll save all the picky rules for later, after you've seen |
| 142 | a bunch of examples. However, we really have to establish some ground |
| 143 | rules before we can dive into the examples: |
| 144 | \begin{itemize} |
| 145 | \item in a normal \UNIX{} installation, \code{sys.prefix} and |
| 146 | \code{sys.exec\_prefix} are both \file{/usr/local}. |
| 147 | \item in a multi-platform \UNIX{} installation, \code{sys.prefix} and |
| 148 | \code{sys.exec\_prefix} are different, and are selected when you |
| 149 | configure and build Python itself. Our canonical example of a |
| 150 | multi-platform installation will have a \code{sys.prefix} of |
| 151 | \file{/usr/local} and a \code{sys.exec\_prefix} of |
| 152 | \file{/usr/local.\filevar{plat}} (for whatever value of \filevar{plat} |
| 153 | is appropriate). |
| 154 | \item the canonical place to install third-party modules is |
| 155 | either \file{\filevar{prefix}/lib/python1.\filevar{X}/site-packages} |
| 156 | or \file{\filevar{exec\_prefix}/lib/python1.\filevar{X}/site-packages}. |
| 157 | These will be referred to as ``the site-packages directories.'' |
| 158 | \end{itemize} |
| 159 | |
| 160 | |
| 161 | \subsubsection{Pure Python module distribution} |
| 162 | |
| 163 | To demonstrate, consider a hypothetical module distribution that |
| 164 | contains one top-level module and a package with two modules: |
| 165 | \begin{tableii}{ll}{module}{Module}{Filename} |
| 166 | \lineii{mymod}{\filenq{mymod.py}} |
| 167 | \lineii{mypkg.mod1}{\filenq{mypkg/mod1.py}} |
| 168 | \lineii{mypkg.mod2}{\filenq{mypkg/mod2.py}} |
| 169 | \end{tableii} |
| 170 | where the filenames are relative to \file{build/lib} after building, or |
| 171 | to some directory in \code{sys.path} after installation. |
| 172 | |
| 173 | The goal of installation is to copy these files into a directory in |
| 174 | \code{sys.path} without interfering with the standard Python library. |
| 175 | The canonical, preferred, and most obvious thing to do is to put them in |
| 176 | the ``site-packages'' directory, which is exactly what the |
| 177 | \command{install} comand does by default: under a normal \UNIX{} Python |
| 178 | installation, |
| 179 | \begin{verbatim} |
| 180 | python setup.py install |
| 181 | \end{verbatim} |
| 182 | installs \file{/usr/local/lib/python1.\filevar{X}/lib/site-packages/mymod.py}, |
| 183 | with the \module{mypkg} package in a \file{mypkg} directory under |
| 184 | \file{site-packages}. |
| 185 | |
| 186 | However, if you were interested in a standard installation, you wouldn't |
| 187 | be reading this section. The next-most-standard thing to do is to |
| 188 | specify a custom prefix to override \code{sys.prefix}. For example: |
| 189 | \begin{verbatim} |
| 190 | python setup.py install --prefix=/home/greg |
| 191 | \end{verbatim} |
| 192 | is a sensible way to install Python modules to your home directory: this |
| 193 | results in the installation of \file{/home/greg/lib/python/mymod.py}, |
| 194 | with the \module{mypkg} modules in \file{/home/greg/lib/python/mypkg/}. |
| 195 | An important point here is that in both this example and the ``plain |
| 196 | vanilla'' example above, the actual installation directory is derived |
| 197 | from the \option{prefix} option. However, when \option{prefix} differs |
| 198 | from \code{sys.prefix}, the installation directory is derived |
| 199 | differently: the Python version and \file{site-packages} are omitted. |
| 200 | (The version number is part of the standard library directory name to |
| 201 | describe the version of the standard library, so it doesn't make sense |
| 202 | to include it in the name of a non-standard-library directory; likewise, |
| 203 | \file{site-packages} is meant to denote non-standard modules living in |
| 204 | the same area as the standard library, so it doesn't make sense to |
| 205 | include it when installing to a non-standard library. [XXX check with |
| 206 | Guido that this reasoning is valid and correct; Fred disagrees!]) |
| 207 | |
| 208 | |
| 209 | \subsubsection{Module distribution with extensions} |
| 210 | |
| 211 | Now let's consider a different hypothetical module distribution, which |
| 212 | consists of a single package, \module{foo}, containing one pure Python |
| 213 | module and one extension module: |
| 214 | \begin{tableii}{ll}{module}{Module}{Filename} |
| 215 | \lineii{foo.pure}{\filenq{foo/pure.py}} |
| 216 | \lineii{foo.ext}{\filenq{foo/ext.so} (or \file{foo/extmodule.so})} |
| 217 | \end{tableii} |
| 218 | In this case, the two modules will be in different locations in the |
| 219 | build tree: \file{build/lib/foo/pure.py} and |
| 220 | \file{build/platlib/foo/ext.so}. (The \file{.so} (``shared object'') |
| 221 | extension isn't universal, but it's the norm on \UNIX-like systems; |
| 222 | under Windows, the extension module will be in \file{foo/ext.pyd} or |
| 223 | \file{foo/extmodule.pyd}.) |
| 224 | |
| 225 | Consider again a standard, plain-vanilla installation: |
| 226 | \begin{verbatim} |
| 227 | python setup.py install |
| 228 | \end{verbatim} |
| 229 | In this case, \emph{both} modules will be installed to the site-packages |
| 230 | directory under \code{sys.exec\_prefix}, e.g. to |
| 231 | \file{/usr/local.\filevar{plat}/lib/python1.\filevar{X}/site-packages} |
| 232 | on a \UNIX{} system where Python was configured with |
| 233 | \samp{--exec-prefix=/usr/local.plat}. (On Windows, again, there is no |
| 234 | site-packages directory and \code{sys.prefix} and |
| 235 | \code{sys.exec\_prefix} are the same---so both modules will just be |
| 236 | installed to \code{sys.prefix}.) |
| 237 | |
| 238 | Of course, we've already established that you're not interested in |
| 239 | standard installations. If you just want to install these modules to |
| 240 | your home directory, and you don't maintain a multi-platform home |
| 241 | directory, no problem---just set the prefix as before: |
| 242 | \begin{verbatim} |
| 243 | python setup.py install --prefix=/home/greg |
| 244 | \end{verbatim} |
| 245 | and both modules will be installed to \file{/home/greg/lib/python}. |
| 246 | |
| 247 | Now let's say your Python installation is in \file{/usr}---as is the |
| 248 | case in many Linux distributions---but your local policy is to install |
| 249 | third-party software to a network-wide \file{/usr/local} and |
| 250 | \file{/usr/local.\filevar{plat}}. That is, \code{sys.prefix} and |
| 251 | \code{sys.exec\_prefix} are both \file{/usr}, and you want Python |
| 252 | modules to be installed to either \file{/usr/local/lib/python} or |
| 253 | \file{/usr/local.\filevar{plat}/lib/python}. This is one case where you |
| 254 | want to specify both \option{prefix} and \option{exec-prefix}: |
| 255 | \begin{verbatim} |
| 256 | python setup.py install --prefix=/usr/local \ |
| 257 | --exec-prefix=/usr/local.plat |
| 258 | \end{verbatim} |
| 259 | An oddity of this situation is that for any given module distribution, |
| 260 | you only have to supply \emph{one} of \option{prefix} and |
| 261 | \option{exec-prefix}, because pure Python distributions are always |
| 262 | installed under \option{prefix}, and extension-containing distributions |
| 263 | are always installed under \option{exec-prefix}. For consistency's |
| 264 | sake, though, it's best always to supply both---and the best way to do |
| 265 | that is by using a system-wide configuration file (see |
| 266 | Section~\ref{sec:config-files}). |
| 267 | |
| 268 | You could use a similar scheme to maintain a multi-platform personal |
| 269 | Python library. For example, if you install lots of stuff to your home |
| 270 | directory (not just Python modules), you might have a complete |
| 271 | \file{\tilde/usr} with \file{include}, \file{man}, \file{lib}, and so |
| 272 | forth. (The advantage of this scheme is that it keeps those mock system |
| 273 | directories out of your home directory and makes it easier to support a |
| 274 | multi-platform personal \file{usr} tree.) If you don't care about a |
| 275 | multi-platform installation, you can just install with |
| 276 | \begin{verbatim} |
| 277 | python setup.py install --prefix=$HOME/usr |
| 278 | \end{verbatim} |
| 279 | But if you want to keep separate \file{usr} trees for each architecture |
| 280 | that you use, you could say |
| 281 | \begin{verbatim} |
| 282 | python setup.py install --prefix=$HOME/usr \ |
| 283 | --exec-prefix=$HOME/usr.plat |
| 284 | \end{verbatim} |
| 285 | for various values of \file{plat}. |
| 286 | |
| 287 | % this paragraph is for Michel Sanner ;-) |
| 288 | (Perceptive readers will note that on a multi-platform Python |
| 289 | installation, multiple identical copies of \file{foo/pure.py} will be |
| 290 | installed, one for each platform. This is deliberate. First, it makes |
| 291 | Python's module search algorithm simpler (XXX check this): when you say |
| 292 | \samp{import foo.pure}, Python searches \code{sys.path} until it finds a |
| 293 | directory containing \file{foo/__init__.py}. When it finds one, that |
| 294 | directory is deemed to be the directory containing the \module{foo} |
| 295 | package for this import. Even if the search algorithm were changed |
| 296 | (necessitating a trip back in time to ``fix'' Python 1.5), the only way |
| 297 | to make multiple candidate \module{foo} directories (one for pure |
| 298 | Python, one for extension modules) would be to make copies of |
| 299 | \file{__init__.py}---in which case, why not make copies of all the pure |
| 300 | Python modules? Second, if you kept pure Python modules related to |
| 301 | extension modules in a platform-shared directory, what happens while you |
| 302 | are upgrading your favourite extension from version 1.0 to 1.1 on |
| 303 | platforms X and Y? After you install 1.1 for platform X, the 1.1 |
| 304 | \file{.py} files will be in the platform-shared directory---but the 1.0 |
| 305 | extensions will still be in the platform Y directory. If the interval |
| 306 | between installing 1.1 for platform X and for platform Y is long---e.g., |
| 307 | there are portability problems with platform Y---then there's a good |
| 308 | probability of a version mismatch between the 1.1 Python modules and the |
| 309 | 1.0 extensions on platform Y. The solution to both problems is to |
| 310 | install separate copies of the pure Python modules for every platform. |
| 311 | In this day and age, unnecessary disk use is no argument.) |
| 312 | |
| 313 | Other ways to support a multi-platform personal Python library are |
| 314 | discussed below, when we cover the \option{install-lib} and |
| 315 | \option{install-platlib} options. |
| 316 | |
| 317 | |
| 318 | % Gory details on the prefix options (still need to work these into the |
| 319 | % surrounding text): |
| 320 | XXX need to finish these rules and give them some context! |
| 321 | \begin{itemize} |
| 322 | \item \code{sys.exec\_prefix} (and the \option{exec-prefix} option) |
| 323 | only matters on a multi-platform installation. If you don't have a |
| 324 | multi-platform installation (or even know what that is), then you |
| 325 | don't care about \option{exec-prefix}. |
| 326 | \item in a normal Windows installation, \code{sys.prefix} and |
| 327 | \code{sys.exec\_prefix} are both \file{C:\bslash Program Files\bslash |
| 328 | Python}; they are never different under Windows (XXX check!). |
| 329 | \item you may supply \emph{both} of \option{prefix} and |
| 330 | \option{exec-prefix}, or \emph{neither} of them, or \emph{just} |
| 331 | \option{prefix}---but you may not supply just \option{exec-prefix}. |
| 332 | \end{itemize} |
| 333 | |
| 334 | |
| 335 | \subsection{Installation directory options} |
| 336 | \label{sec:install-dirs} |
| 337 | |
| 338 | Most of the time, it's enough to specify just \option{prefix} (and |
| 339 | possibly \option{exec-prefix})---your modules are installed to |
| 340 | \file{lib/python} under one or the other, you add the appropriate |
| 341 | directory to \code{sys.path}, and that's it. |
| 342 | |
| 343 | However, there will inevitably be times when you want finer control over |
| 344 | the installation directories, and that is when the \option{install-lib}, |
| 345 | \option{install-platlib}, and \option{install-path} options are |
| 346 | essential. Normally, \option{install-lib} and \option{install-platlib} |
| 347 | are simply the directories where pure Python modules and extension |
| 348 | modules, respectively, are installed. That is, top-level modules |
| 349 | (modules not in a package) are installed straight to |
| 350 | \option{install-lib} (or \option{install-platlib} if there are any |
| 351 | extensions in the module distribution). (If \option{install-path} is |
| 352 | supplied, then things are a bit more complex; we'll deal with that |
| 353 | below.) |
| 354 | |
| 355 | Normally, \option{install-lib} and \option{install-platlib} are derived |
| 356 | from \option{prefix} and/or \option{exec-prefix}. For example, if you |
| 357 | don't supply anything, then \option{prefix} defaults to |
| 358 | \code{sys.prefix}, and \option{install-lib} defaults to |
| 359 | \file{\filevar{prefix}/lib/python1.\filevar{X}/site-packages}. If you |
| 360 | supply \option{prefix} but not \option{install-lib}, then |
| 361 | \option{install-lib} defaults to \file{\filevar{prefix}/lib/python} |
| 362 | (unless you just happen to supply a prefix which equals |
| 363 | \code{sys.prefix}, which is treated the same as if you don't supply |
| 364 | \option{prefix} at all). (The rules for \option{exec-prefix} and |
| 365 | \option{install-platlib} are a bit more complex; the following examples |
| 366 | should clarify. Consult the Distutils source for the gory details.) |
| 367 | |
| 368 | To illustrate, let's go back to our hypothetical pure-Python module |
| 369 | distribution containing \module{mymod}, \module{mypkg.mod1}, and |
| 370 | \module{mypkg.mod2}. If you maintain a personal stash of Python modules |
| 371 | in your home directory, but don't like the \file{\tilde/lib/python} |
| 372 | convention, no problem---you can put the modules right in a |
| 373 | \file{\tilde/python} directory with |
| 374 | \begin{verbatim} |
| 375 | python setup.py install --install-lib=$HOME/python |
| 376 | \end{verbatim} |
| 377 | which will install \file{\$HOME/python/mymod.py}, |
| 378 | \file{\$HOME/python/mypkg/mod1.py}, and |
| 379 | \file{\$HOME/python/mypkg/mod2.py}. |
| 380 | |
| 381 | If you happen to install a module distribution that contains extensions, |
| 382 | again that's no problem---in the absence of \option{exec-prefix}, |
| 383 | \option{install-platlib} defaults to \option{install-lib}, so the above |
| 384 | example will also put extension modules in \file{\$HOME/python}. |
| 385 | (XXX is this correct? is this the best way to describe it? should it be |
| 386 | implemented this way or some other way? how should it be described?) |
| 387 | |
| 388 | This may not be what you want, though, if you maintain a multi-platform |
| 389 | stash of Python modules in your home directory. In that case, you need |
| 390 | to specify \option{install-platlib}---this is the directory where module |
| 391 | distributions with extensions will be installed. For example, if you |
| 392 | keep pure Python module distributions in \file{\tilde/python} and |
| 393 | extension distributions in \file{\tilde/python.plat}: |
| 394 | \begin{verbatim} |
| 395 | python setup.py install --install-lib=$HOME/python \ |
| 396 | --install-platlib=$HOME/python.plat |
| 397 | \end{verbatim} |
| 398 | (Just as with \option{prefix} and \option{exec-prefix}, it's only |
| 399 | necessary to supply one of \option{install-lib} and |
| 400 | \option{install-platlib} for any given module distribution, but to |
| 401 | ensure consistency you should always supply them both using a |
| 402 | configuration file (section~\ref{sec:config-files}).) |
| 403 | |
| 404 | An alternate way to maintain a multi-platform personal Python library is |
| 405 | in \file{\tilde/lib/python} and \file{\tilde/lib/python.plat}. In that |
| 406 | case, you can get away with supplying \option{prefix} and |
| 407 | \option{install-platlib}: |
| 408 | \begin{verbatim} |
| 409 | python setup.py install --prefix=$HOME \ |
| 410 | --install-platlib=$HOME/lib/python.plat |
| 411 | \end{verbatim} |
| 412 | |
| 413 | Finally, the \option{install-path} option, which exists mainly to gum up |
| 414 | the whole works---but in a productive (and important) way. |
| 415 | Specifically, \option{install-path} exists to give a directory of their |
| 416 | own to module distributions that wouldn't otherwise have one, i.e.\ that |
| 417 | are not distributed as a (Python) package. |
| 418 | |
| 419 | Consider a module distribution, Foo, that consists of (pure Python) |
| 420 | modules \module{foobar}, \module{foobaz}, and \module{fooqux}. |
| 421 | Obviously these are related, and if the project had started in the |
| 422 | Python 1.5 era (and doesn't worry about backwards compatibility with |
| 423 | Python 1.4), they probably would be packaged up and called |
| 424 | \module{foo.bar}, \module{foo.baz}, and \module{foo.qux}. |
| 425 | Unfortunately, they aren't, but we still want the Foo modules to go into |
| 426 | a directory of their own. |
| 427 | |
| 428 | Normally, this will be taken care of by the module developer: he adds a |
| 429 | line \samp{install_path = 'Foo'} to his setup script, which has the |
| 430 | following consequences: |
| 431 | \begin{enumerate} |
| 432 | \item instead of \option{install-lib} the modules would be installed in |
| 433 | \file{\filevar{install-lib}/Foo} |
| 434 | \item if \option{install-lib} is the same as the default |
| 435 | \option{install-lib}---e.g., you supplied neither \option{prefix} or |
| 436 | \option{install-lib}---then a \file{Foo.pth} will be created in |
| 437 | \option{install-lib}, so that Python adds |
| 438 | \file{\filevar{install-lib}/Foo} to \code{sys.path} |
| 439 | \item if \option{install-lib} is not the default, then a warning will be |
| 440 | printed, reminding you to add \file{\filevar{install-lib}/Foo} to |
| 441 | \code{sys.path} yourself, such as with the \code{PYTHONPATH} |
| 442 | environment variable |
| 443 | \end{enumerate} |
| 444 | |
| 445 | Thus, you as a module installer have to be aware of the |
| 446 | \option{install-path} option---especially if you maintain a personal |
| 447 | stash of Python modules and don't have write permission to the standard |
| 448 | library, so Distutils can't create \file{.pth} files for you---but you |
| 449 | don't often have to supply it yourself. There are situations in which |
| 450 | you might want to supply it, though: |
| 451 | \begin{itemize} |
| 452 | \item a module developer forgot to include it (the distribution really |
| 453 | should go in a directory of its own, but it won't unless you make it) |
| 454 | \item you want to override the \option{install-path} supplied by the |
| 455 | developer (e.g., you'd rather have a huge jumble of files in |
| 456 | \file{site-packages} than make Python wade through a bunch of |
| 457 | \file{.pth} files at startup) |
| 458 | \end{itemize} |
| 459 | |
| 460 | The first case is easy: say we're dealing with the Foo distribution |
| 461 | again, but the developer forgot to include \option{install-path}. No |
| 462 | problem, you can supply it on the command line: |
| 463 | \begin{verbatim} |
| 464 | python setup.py install --install-path=Foo |
| 465 | \end{verbatim} |
| 466 | Note that this will work just fine if you supply \option{prefix} or |
| 467 | \option{install-lib}---but of course, you'll probably have to ensure |
| 468 | that the \file{Foo} directory is in \code{sys.path} yourself. |
| 469 | |
| 470 | If you're really fanatical about keeping track of what you have |
| 471 | installed, you might want to supply your own \option{install-path} that |
| 472 | records the version as well as the name of the module distribution; this |
| 473 | overrides any \option{install-path} included by the module developer in |
| 474 | the setup script: |
| 475 | \begin{verbatim} |
| 476 | python setup.py install --install-path=Foo-1.3 |
| 477 | \end{verbatim} |
| 478 | |
| 479 | Finally, you can disable \option{install-path} entirely: |
| 480 | \begin{verbatim} |
| 481 | python setup.py install --install-path='' |
| 482 | \end{verbatim} |
| 483 | ...but the mess that will result (modules from many different |
| 484 | distributions in the same \option{install-lib} and |
| 485 | \option{install-platlib} directories) is your own problem. |
| 486 | |
| 487 | % Points to make |
| 488 | % * only one of prefix or exec_prefix matters |
| 489 | % * don't have to specify exec_prefix unless != prefix |
| 490 | % * thus, usually enough to supply prefix |
| 491 | % * only have to supply install_lib if you don't like |
| 492 | % "prefix/lib/python" |
| 493 | % * likewise for install_platlib and exec_prefix |
| 494 | % * don't have to supply install_platlib unless != install_lib (??) |
| 495 | % * in the absence of install_path, top-level modules wind up in |
| 496 | % install_lib or install_platlib |
| 497 | In case you're interested, here are the exact rules for how |
| 498 | \option{install-lib} and \option{install-platlib} are initialized, and |
| 499 | how they and \option{install-path} affect where modules (pure Python and |
| 500 | extensions) are installed to: |
| 501 | \begin{itemize} |
| 502 | \item If you don't supply \option{prefix} (and possibly |
| 503 | \option{exec-prefix}), then \option{install-lib} and |
| 504 | \option{install-platlib} will be, respectively, |
| 505 | \file{\filevar{\$prefix}/lib/python1.\filevar{X}/site-packages} and |
| 506 | \file{\filevar{\$exec\_prefix}/lib/python1.\filevar{X}/site-packages}. In a |
| 507 | normal \UNIX{} installation, both of these resolve to |
| 508 | \file{/usr/local/lib/python1.\filevar{X}/site-packages}. |
| 509 | \item in the absence of an \option{install-path} option, top-level |
| 510 | modules and packages from a pure Python distribution are installed to |
| 511 | \option{install-lib} |
| 512 | \item in the absence of an \option{install-path} option, top-level |
| 513 | modules and packages from a distribution that contains \emph{any} |
| 514 | extension modules are installed to \option{install-platlib}. |
| 515 | \item \emph{there're more, but I don't remember everything offhand} |
| 516 | %\item \option{install-lib} is initialized from \option{prefix} (which |
| 517 | % in turn is initialized from \code{sys.prefix})---so you should |
| 518 | \end{itemize} |
| 519 | |
| 520 | |
| 521 | \section{Custom Installation (Windows)} |
| 522 | \label{sec:custom-install-windows} |
| 523 | |
| 524 | \comingsoon |
| 525 | |
| 526 | |
| 527 | \section{Configuration Files} |
| 528 | \label{sec:config-files} |
| 529 | |
| 530 | \comingsoon |
| 531 | |
| 532 | |
| 533 | |
| 534 | \end{document} |