Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 1 | \documentclass{howto} |
Greg Ward | 7593eb3 | 2000-04-09 03:59:15 +0000 | [diff] [blame] | 2 | \usepackage{distutils} |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 3 | |
| 4 | \title{Installing Python Modules} |
| 5 | |
| 6 | % The audience for this document includes people who don't know anything |
| 7 | % about Python and aren't about to learn the language just in order to |
| 8 | % install and maintain it for their users, i.e. system administrators. |
| 9 | % Thus, I have to be sure to explain the basics at some point: |
| 10 | % sys.path and PYTHONPATH at least. Should probably give pointers to |
| 11 | % other docs on "import site", PYTHONSTARTUP, PYTHONHOME, etc. |
| 12 | % |
| 13 | % Also, I need to take into account that most modules out there don't |
| 14 | % (yet) use Distutils: briefly explain the old Makefile.pre.in |
| 15 | % convention (maybe move material from the E&E manual to here?), and |
| 16 | % explain where to copy .py and .so files manually if the distribution |
| 17 | % doesn't provide a mechanism for doing so. |
| 18 | % |
| 19 | % Finally, it might be useful to include all the material from my "Care |
| 20 | % and Feeding of a Python Installation" talk in here somewhere. Yow! |
| 21 | |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 22 | \author{Greg Ward} |
| 23 | \authoraddress{E-mail: \email{gward@python.net}} |
| 24 | |
Greg Ward | e3cca26 | 2000-08-31 16:36:31 +0000 | [diff] [blame] | 25 | \makeindex |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 26 | |
| 27 | \begin{document} |
| 28 | |
| 29 | \maketitle |
| 30 | |
Greg Ward | e3cca26 | 2000-08-31 16:36:31 +0000 | [diff] [blame] | 31 | \begin{abstract} |
| 32 | \noindent |
| 33 | This document describes the Python Distribution Utilities |
| 34 | (``Distutils'') from the end-user's point-of-view, describing how to |
| 35 | extend the capabilities of a standard Python installation by building |
| 36 | and installing third-party Python modules and extensions. |
| 37 | \end{abstract} |
| 38 | |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 39 | %\begin{abstract} |
| 40 | %\noindent |
| 41 | %Abstract this! |
| 42 | %\end{abstract} |
| 43 | |
| 44 | \tableofcontents |
| 45 | |
| 46 | \section{Introduction} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 47 | \label{intro} |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 48 | |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame] | 49 | Although Python's extensive standard library covers many programming |
| 50 | needs, there often comes a time when you need to add some new |
| 51 | functionality to your Python installation in the form of third-party |
| 52 | modules. This might be necessary to support your own programming, or to |
| 53 | support an application that you want to use and that happens to be |
| 54 | written in Python. |
| 55 | |
| 56 | In the past, there has been little support for adding third-party |
| 57 | modules to an existing Python installation. With the introduction of |
Fred Drake | 01df453 | 2000-06-30 03:36:41 +0000 | [diff] [blame] | 58 | the Python Distribution Utilities (Distutils for short) in Python 2.0, |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame] | 59 | this is starting to change. Not everything will change overnight, |
| 60 | though, so while this document concentrates on installing module |
| 61 | distributions that use the Distutils, we will also spend some time |
| 62 | dealing with the old ways. |
| 63 | |
| 64 | This document is aimed primarily at the people who need to install |
| 65 | third-party Python modules: end-users and system administrators who just |
| 66 | need to get some Python application running, and existing Python |
| 67 | programmers who want to add some new goodies to their toolbox. You |
| 68 | don't need to know Python to read this document; there will be some |
| 69 | brief forays into using Python's interactive mode to explore your |
| 70 | installation, but that's it. If you're looking for information on how |
| 71 | to distribute your own Python modules so that others may use them, see |
Fred Drake | 01df453 | 2000-06-30 03:36:41 +0000 | [diff] [blame] | 72 | the \citetitle[../dist/dist.html]{Distributing Python Modules} manual. |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 73 | |
| 74 | |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame] | 75 | \subsection{Best case: trivial installation} |
Greg Ward | 1ed49ee | 2000-09-13 00:00:58 +0000 | [diff] [blame] | 76 | \label{trivial-install} |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame] | 77 | |
| 78 | In the best case, someone will have prepared a special version of the |
| 79 | module distribution you want to install that is targeted specifically at |
| 80 | your platform and is installed just like any other software on your |
| 81 | platform. For example, the module developer might make an executable |
| 82 | installer available for Windows users, an RPM package for users of |
| 83 | RPM-based Linux systems (Red Hat, SuSE, Mandrake, and many others), a |
| 84 | Debian package for users of Debian-based Linux systems (Debian proper, |
| 85 | Caldera, Corel, etc.), and so forth. |
| 86 | |
| 87 | In that case, you would download the installer appropriate to your |
Greg Ward | c392caa | 2000-04-11 02:00:26 +0000 | [diff] [blame] | 88 | platform and do the obvious thing with it: run it if it's an executable |
| 89 | installer, \code{rpm --install} it if it's an RPM, etc. You don't need |
| 90 | to run Python or a setup script, you don't need to compile |
| 91 | anything---you might not even need to read any instructions (although |
| 92 | it's always a good idea to do so anyways). |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame] | 93 | |
| 94 | Of course, things will not always be that easy. You might be interested |
Greg Ward | c392caa | 2000-04-11 02:00:26 +0000 | [diff] [blame] | 95 | in a module distribution that doesn't have an easy-to-use installer for |
| 96 | your platform. In that case, you'll have to start with the source |
| 97 | distribution released by the module's author/maintainer. Installing |
| 98 | from a source distribution is not too hard, as long as the modules are |
| 99 | packaged in the standard way. The bulk of this document is about |
| 100 | building and installing modules from standard source distributions. |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 101 | |
| 102 | |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame] | 103 | \subsection{The new standard: Distutils} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 104 | \label{new-standard} |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame] | 105 | |
| 106 | If you download a module source distribution, you can tell pretty |
Greg Ward | 19c67f8 | 2000-06-24 01:33:16 +0000 | [diff] [blame] | 107 | quickly if it was packaged and distributed in the standard way, i.e. |
| 108 | using the Distutils. First, the distribution's name and version number |
| 109 | will be featured prominently in the name of the downloaded archive, e.g. |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame] | 110 | \file{foo-1.0.tar.gz} or \file{widget-0.9.7.zip}. Next, the archive |
| 111 | will unpack into a similarly-named directory: \file{foo-1.0} or |
| 112 | \file{widget-0.9.7}. Additionally, the distribution will contain a |
| 113 | setup script \file{setup.py}, and a \file{README.txt} (or possibly |
| 114 | \file{README}), which should explain that building and installing the |
| 115 | module distribution is a simple matter of running |
| 116 | \begin{verbatim} |
| 117 | python setup.py install |
| 118 | \end{verbatim} |
| 119 | |
| 120 | If all these things are true, then you already know how to build and |
| 121 | install the modules you've just downloaded: run the command above. |
| 122 | Unless you need to install things in a non-standard way or customize the |
| 123 | build process, you don't really need this manual. Or rather, the above |
| 124 | command is everything you need to get out of this manual. |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 125 | |
| 126 | |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame] | 127 | \subsection{The old way: no standards} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 128 | \label{old-way} |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 129 | |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame] | 130 | Before the Distutils, there was no infrastructure to support installing |
| 131 | third-party modules in a consistent, standardized way. Thus, it's not |
| 132 | really possible to write a general manual for installing Python modules |
| 133 | that don't use the Distutils; the only truly general statement that can |
Greg Ward | c392caa | 2000-04-11 02:00:26 +0000 | [diff] [blame] | 134 | be made is, ``Read the module's own installation instructions.'' |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame] | 135 | |
Greg Ward | 19c67f8 | 2000-06-24 01:33:16 +0000 | [diff] [blame] | 136 | However, if such instructions exist at all, they are often woefully |
Greg Ward | c392caa | 2000-04-11 02:00:26 +0000 | [diff] [blame] | 137 | inadequate and targeted at experienced Python developers. Such users |
| 138 | are already familiar with how the Python library is laid out on their |
| 139 | platform, and know where to copy various files in order for Python to |
| 140 | find them. This document makes no such assumptions, and explains how |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 141 | the Python library is laid out on three major platforms (\UNIX, Windows, |
| 142 | and MacOS), so that you can understand what happens when the Distutils |
Greg Ward | c392caa | 2000-04-11 02:00:26 +0000 | [diff] [blame] | 143 | do their job \emph{and} know how to install modules manually when the |
| 144 | module author fails to provide a setup script. |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame] | 145 | |
| 146 | Additionally, while there has not previously been a standard |
| 147 | installation mechanism, Python has had some standard machinery for |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 148 | building extensions on \UNIX{} since Python \XXX{version?}. This |
| 149 | machinery (the \file{Makefile.pre.in} file) is superseded by the |
| 150 | Distutils, but it will no doubt live on in older module distributions |
| 151 | for a while. This \file{Makefile.pre.in} mechanism is documented in |
| 152 | the \citetitle[../ext/ext.html]{Extending \& Embedding Python} manual, |
| 153 | but that manual is aimed at module developers---hence, we include |
| 154 | documentation for builders/installers here. |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame] | 155 | |
| 156 | All of the pre-Distutils material is tucked away in |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 157 | section~\ref{pre-distutils}. |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 158 | |
| 159 | |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 160 | \section{Standard Build and Install} |
Greg Ward | 1ed49ee | 2000-09-13 00:00:58 +0000 | [diff] [blame] | 161 | \label{standard-install} |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 162 | |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 163 | As described in section~\ref{new-standard}, building and installing |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame] | 164 | a module distribution using the Distutils is usually one simple command: |
| 165 | \begin{verbatim} |
| 166 | python setup.py install |
| 167 | \end{verbatim} |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 168 | On \UNIX, you'd run this command from a shell prompt; on Windows, you |
Greg Ward | e24f05e | 2000-09-12 23:55:19 +0000 | [diff] [blame] | 169 | have to open a command prompt window (``DOS box'') and do it there; on |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 170 | MacOS, things are a tad more complicated (see below). |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame] | 171 | |
| 172 | |
| 173 | \subsection{Platform variations} |
Greg Ward | 1ed49ee | 2000-09-13 00:00:58 +0000 | [diff] [blame] | 174 | \label{platform-variations} |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame] | 175 | |
| 176 | You should always run the setup command from the distribution root |
| 177 | directory, i.e. the top-level subdirectory that the module source |
| 178 | distribution unpacks into. For example, if you've just downloaded a |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 179 | module source distribution \file{foo-1.0.tar.gz} onto a |
| 180 | \UNIX{} system, the normal thing to do is: |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame] | 181 | \begin{verbatim} |
| 182 | gunzip -c foo-1.0.tar.gz | tar xf - # unpacks into directory foo-1.0 |
| 183 | cd foo-1.0 |
| 184 | python setup.py install |
| 185 | \end{verbatim} |
| 186 | |
Greg Ward | e24f05e | 2000-09-12 23:55:19 +0000 | [diff] [blame] | 187 | On Windows, you'd probably download \file{foo-1.0.zip}. If you |
| 188 | downloaded the archive file to \file{C:\textbackslash{}Temp}, then it |
| 189 | would unpack into \file{C:\textbackslash{}Temp\textbackslash{}foo-1.0}; |
| 190 | you can use either a GUI archive manipulator (such as WinZip) or a |
| 191 | command-line tool (such as \program{unzip} or \program{pkunzip}) to |
| 192 | unpack the archive. Then, open a command prompt window (``DOS box''), |
| 193 | and run: |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame] | 194 | \begin{verbatim} |
Greg Ward | e24f05e | 2000-09-12 23:55:19 +0000 | [diff] [blame] | 195 | cd c:\Temp\foo-1.0 |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame] | 196 | python setup.py install |
| 197 | \end{verbatim} |
| 198 | |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 199 | On MacOS, you have to go through a bit more effort to supply |
Greg Ward | e24f05e | 2000-09-12 23:55:19 +0000 | [diff] [blame] | 200 | command-line arguments to the setup script: |
| 201 | \begin{itemize} |
| 202 | \item hit option-double-click on the script's icon (or option-drop it |
| 203 | onto the Python interpreter's icon) |
| 204 | \item press the ``Set unix-style command line'' button |
| 205 | \item set the ``Keep stdio window open on termination'' if you're |
| 206 | interested in seeing the output of the setup script (which is usually |
| 207 | voluminous and often useful) |
Greg Ward | 15f5e2a | 2000-09-26 02:54:43 +0000 | [diff] [blame] | 208 | \item when the command-line dialog pops up, enter ``install'' (you |
Greg Ward | e24f05e | 2000-09-12 23:55:19 +0000 | [diff] [blame] | 209 | can, of course, enter any Distutils command-line as described in this |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 210 | document or in \citetitle[../dist/dist.html]{Distributing Python |
| 211 | Modules}: just leave off the initial \code{python setup.py} and |
| 212 | you'll be fine) |
Greg Ward | e24f05e | 2000-09-12 23:55:19 +0000 | [diff] [blame] | 213 | \end{itemize} |
| 214 | \XXX{this should change: every Distutils setup script will need |
| 215 | command-line arguments for every run (and should probably keep stdout |
| 216 | around), so all this should happen automatically for setup scripts} |
Greg Ward | c392caa | 2000-04-11 02:00:26 +0000 | [diff] [blame] | 217 | |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame] | 218 | |
| 219 | \subsection{Splitting the job up} |
Greg Ward | 1ed49ee | 2000-09-13 00:00:58 +0000 | [diff] [blame] | 220 | \label{splitting-up} |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame] | 221 | |
| 222 | Running \code{setup.py install} builds and installs all modules in one |
Greg Ward | 14deaae | 2000-09-11 00:33:15 +0000 | [diff] [blame] | 223 | run. If you prefer to work incrementally---especially useful if you |
| 224 | want to customize the build process, or if things are going wrong---you |
| 225 | can use the setup script to do one thing at a time. This is |
Greg Ward | 3e7b133 | 2000-05-30 03:00:43 +0000 | [diff] [blame] | 226 | particularly helpful when the build and install will be done by |
| 227 | different users---e.g., you might want to build a module distribution |
| 228 | and hand it off to a system administrator for installation (or do it |
| 229 | yourself, with super-user privileges). |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame] | 230 | |
| 231 | For example, you can build everything in one step, and then install |
| 232 | everything in a second step, by invoking the setup script twice: |
| 233 | \begin{verbatim} |
| 234 | python setup.py build |
| 235 | python setup.py install |
| 236 | \end{verbatim} |
| 237 | (If you do this, you will notice that running the \command{install} |
Greg Ward | 14deaae | 2000-09-11 00:33:15 +0000 | [diff] [blame] | 238 | command first runs the \command{build} command, which---in this |
| 239 | case---quickly notices that it has nothing to do, since everything in |
| 240 | the \file{build} directory is up-to-date.) |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 241 | |
Greg Ward | 14deaae | 2000-09-11 00:33:15 +0000 | [diff] [blame] | 242 | You may not need this ability to break things down often if all you do |
| 243 | is install modules downloaded off the 'net, but it's very handy for more |
| 244 | advanced tasks. If you get into distributing your own Python modules |
| 245 | and extensions, you'll run lots of individual Distutils commands on |
| 246 | their own. |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 247 | |
| 248 | |
Greg Ward | c392caa | 2000-04-11 02:00:26 +0000 | [diff] [blame] | 249 | \subsection{How building works} |
Greg Ward | 1ed49ee | 2000-09-13 00:00:58 +0000 | [diff] [blame] | 250 | \label{how-build-works} |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 251 | |
Greg Ward | c392caa | 2000-04-11 02:00:26 +0000 | [diff] [blame] | 252 | As implied above, the \command{build} command is responsible for putting |
| 253 | the files to install into a \emph{build directory}. By default, this is |
| 254 | \file{build} under the distribution root; if you're excessively |
| 255 | concerned with speed, or want to keep the source tree pristine, you can |
Greg Ward | 4eaa3bf | 2000-04-19 22:44:25 +0000 | [diff] [blame] | 256 | change the build directory with the \longprogramopt{build-base} option. |
| 257 | For example: |
Greg Ward | c392caa | 2000-04-11 02:00:26 +0000 | [diff] [blame] | 258 | \begin{verbatim} |
| 259 | python setup.py build --build-base=/tmp/pybuild/foo-1.0 |
| 260 | \end{verbatim} |
| 261 | (Or you could do this permanently with a directive in your system or |
| 262 | personal Distutils configuration file; see |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 263 | section~\ref{config-files}.) Normally, this isn't necessary. |
Greg Ward | c392caa | 2000-04-11 02:00:26 +0000 | [diff] [blame] | 264 | |
| 265 | The default layout for the build tree is as follows: |
| 266 | \begin{verbatim} |
| 267 | --- build/ --- lib/ |
| 268 | or |
| 269 | --- build/ --- lib.<plat>/ |
| 270 | temp.<plat>/ |
| 271 | \end{verbatim} |
| 272 | where \code{<plat>} expands to a brief description of the current |
Greg Ward | 7ef2ba7 | 2000-10-22 01:40:08 +0000 | [diff] [blame] | 273 | OS/hardware platform and Python version. The first form, with just a |
| 274 | \file{lib} directory, is used for ``pure module distributions''---that |
| 275 | is, module distributions that include only pure Python modules. If a |
| 276 | module distribution contains any extensions (modules written in C/C++), |
| 277 | then the second form, with two \code{<plat>} directories, is used. In |
| 278 | that case, the \file{temp.\filevar{plat}} directory holds temporary |
| 279 | files generated by the compile/link process that don't actually get |
| 280 | installed. In either case, the \file{lib} (or |
Greg Ward | c392caa | 2000-04-11 02:00:26 +0000 | [diff] [blame] | 281 | \file{lib.\filevar{plat}}) directory contains all Python modules (pure |
| 282 | Python and extensions) that will be installed. |
| 283 | |
| 284 | In the future, more directories will be added to handle Python scripts, |
| 285 | documentation, binary executables, and whatever else is needed to handle |
Greg Ward | d5faa7e | 2000-04-12 01:42:19 +0000 | [diff] [blame] | 286 | the job of installing Python modules and applications. |
Greg Ward | c392caa | 2000-04-11 02:00:26 +0000 | [diff] [blame] | 287 | |
| 288 | |
| 289 | \subsection{How installation works} |
Greg Ward | 1ed49ee | 2000-09-13 00:00:58 +0000 | [diff] [blame] | 290 | \label{how-install-works} |
Greg Ward | c392caa | 2000-04-11 02:00:26 +0000 | [diff] [blame] | 291 | |
| 292 | After the \command{build} command runs (whether you run it explicitly, |
| 293 | or the \command{install} command does it for you), the work of the |
| 294 | \command{install} command is relatively simple: all it has to do is copy |
| 295 | everything under \file{build/lib} (or \file{build/lib.\filevar{plat}}) |
| 296 | to your chosen installation directory. |
| 297 | |
| 298 | If you don't choose an installation directory---i.e., if you just run |
| 299 | \code{setup.py install}---then the \command{install} command installs to |
| 300 | the standard location for third-party Python modules. This location |
| 301 | varies by platform and by how you built/installed Python itself. On |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 302 | \UNIX{} and MacOS, it also depends on whether the module distribution |
Greg Ward | c392caa | 2000-04-11 02:00:26 +0000 | [diff] [blame] | 303 | being installed is pure Python or contains extensions (``non-pure''): |
Greg Ward | d5faa7e | 2000-04-12 01:42:19 +0000 | [diff] [blame] | 304 | \begin{tableiv}{l|l|l|c}{textrm}% |
| 305 | {Platform}{Standard installation location}{Default value}{Notes} |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 306 | \lineiv{\UNIX{} (pure)} |
Fred Drake | 01df453 | 2000-06-30 03:36:41 +0000 | [diff] [blame] | 307 | {\filenq{\filevar{prefix}/lib/python2.0/site-packages}} |
| 308 | {\filenq{/usr/local/lib/python2.0/site-packages}} |
Greg Ward | 502d2b4 | 2000-04-12 14:20:15 +0000 | [diff] [blame] | 309 | {(1)} |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 310 | \lineiv{\UNIX{} (non-pure)} |
Fred Drake | 01df453 | 2000-06-30 03:36:41 +0000 | [diff] [blame] | 311 | {\filenq{\filevar{exec-prefix}/lib/python2.0/site-packages}} |
| 312 | {\filenq{/usr/local/lib/python2.0/site-packages}} |
Greg Ward | 502d2b4 | 2000-04-12 14:20:15 +0000 | [diff] [blame] | 313 | {(1)} |
Greg Ward | d5faa7e | 2000-04-12 01:42:19 +0000 | [diff] [blame] | 314 | \lineiv{Windows} |
Greg Ward | 4eaa3bf | 2000-04-19 22:44:25 +0000 | [diff] [blame] | 315 | {\filenq{\filevar{prefix}}} |
Greg Ward | 4756e5f | 2000-04-19 22:40:12 +0000 | [diff] [blame] | 316 | {\filenq{C:\textbackslash{}Python}} |
Greg Ward | 502d2b4 | 2000-04-12 14:20:15 +0000 | [diff] [blame] | 317 | {(2)} |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 318 | \lineiv{MacOS (pure)} |
Greg Ward | 7ef2ba7 | 2000-10-22 01:40:08 +0000 | [diff] [blame] | 319 | {\filenq{\filevar{prefix}:Lib:site-packages}} |
| 320 | {\filenq{Python:Lib:site-packages}} |
Greg Ward | d5faa7e | 2000-04-12 01:42:19 +0000 | [diff] [blame] | 321 | {} |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 322 | \lineiv{MacOS (non-pure)} |
Greg Ward | 7ef2ba7 | 2000-10-22 01:40:08 +0000 | [diff] [blame] | 323 | {\filenq{\filevar{prefix}:Lib:site-packages}} |
| 324 | {\filenq{Python:Lib:site-packages}} |
Greg Ward | d5faa7e | 2000-04-12 01:42:19 +0000 | [diff] [blame] | 325 | {} |
| 326 | \end{tableiv} |
| 327 | |
| 328 | \noindent Notes: |
| 329 | \begin{description} |
Greg Ward | 502d2b4 | 2000-04-12 14:20:15 +0000 | [diff] [blame] | 330 | \item[(1)] Most Linux distributions include Python as a standard part of |
| 331 | the system, so \filevar{prefix} and \filevar{exec-prefix} are usually |
| 332 | both \file{/usr} on Linux. If you build Python yourself on Linux (or |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 333 | any \UNIX-like system), the default \filevar{prefix} and |
Greg Ward | 502d2b4 | 2000-04-12 14:20:15 +0000 | [diff] [blame] | 334 | \filevar{exec-prefix} are \file{/usr/local}. |
| 335 | \item[(2)] The default installation directory on Windows was |
Greg Ward | 4eaa3bf | 2000-04-19 22:44:25 +0000 | [diff] [blame] | 336 | \file{C:\textbackslash{}Program Files\textbackslash{}Python} under |
| 337 | Python 1.6a1, 1.5.2, and earlier. |
Greg Ward | d5faa7e | 2000-04-12 01:42:19 +0000 | [diff] [blame] | 338 | \end{description} |
| 339 | |
Greg Ward | c392caa | 2000-04-11 02:00:26 +0000 | [diff] [blame] | 340 | \filevar{prefix} and \filevar{exec-prefix} stand for the directories |
| 341 | that Python is installed to, and where it finds its libraries at |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 342 | run-time. They are always the same under Windows and MacOS, and very |
| 343 | often the same under \UNIX. You can find out what your Python |
Greg Ward | c392caa | 2000-04-11 02:00:26 +0000 | [diff] [blame] | 344 | installation uses for \filevar{prefix} and \filevar{exec-prefix} by |
| 345 | running Python in interactive mode and typing a few simple commands. |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 346 | Under \UNIX, just type \code{python} at the shell prompt; under Windows, |
| 347 | run ``Python 2.0 (interpreter)'' \XXX{right?}; under MacOS, \XXX{???}. |
Fred Drake | 01df453 | 2000-06-30 03:36:41 +0000 | [diff] [blame] | 348 | Once the interpreter is started, you type Python code at the |
| 349 | \samp{>>> } prompt. For example, on my Linux system, I type the three |
| 350 | Python statements shown below, and get the output as shown, to find |
| 351 | out my \filevar{prefix} and \filevar{exec-prefix}: |
| 352 | |
Greg Ward | c392caa | 2000-04-11 02:00:26 +0000 | [diff] [blame] | 353 | \begin{verbatim} |
| 354 | Python 1.5.2 (#1, Apr 18 1999, 16:03:16) [GCC pgcc-2.91.60 19981201 (egcs-1.1.1 on linux2 |
| 355 | Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam |
| 356 | >>> import sys |
| 357 | >>> sys.prefix |
| 358 | '/usr' |
| 359 | >>> sys.exec_prefix |
| 360 | '/usr' |
| 361 | \end{verbatim} |
| 362 | |
Greg Ward | 7ef2ba7 | 2000-10-22 01:40:08 +0000 | [diff] [blame] | 363 | If you don't want to install modules to the standard location, or if you |
| 364 | don't have permission to write there, then you need to read about |
| 365 | alternate installations in section~\ref{alt-install}. If you want to |
| 366 | customize your installation directories more heavily, see |
| 367 | section~\ref{custom-install} on custom installations. |
Greg Ward | c392caa | 2000-04-11 02:00:26 +0000 | [diff] [blame] | 368 | |
| 369 | |
| 370 | % This rather nasty macro is used to generate the tables that describe |
| 371 | % each installation scheme. It's nasty because it takes two arguments |
| 372 | % for each "slot" in an installation scheme, there will soon be more |
| 373 | % than five of these slots, and TeX has a limit of 10 arguments to a |
| 374 | % macro. Uh-oh. |
| 375 | |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 376 | \newcommand{\installscheme}[8] |
| 377 | {\begin{tableiii}{lll}{textrm} |
| 378 | {Type of file} |
| 379 | {Installation Directory} |
| 380 | {Override option} |
| 381 | \lineiii{pure module distribution} |
| 382 | {\filevar{#1}\filenq{#2}} |
Greg Ward | a021aca | 2000-04-19 22:34:11 +0000 | [diff] [blame] | 383 | {\longprogramopt{install-purelib}} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 384 | \lineiii{non-pure module distribution} |
| 385 | {\filevar{#3}\filenq{#4}} |
Greg Ward | a021aca | 2000-04-19 22:34:11 +0000 | [diff] [blame] | 386 | {\longprogramopt{install-platlib}} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 387 | \lineiii{scripts} |
| 388 | {\filevar{#5}\filenq{#6}} |
Greg Ward | a021aca | 2000-04-19 22:34:11 +0000 | [diff] [blame] | 389 | {\longprogramopt{install-scripts}} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 390 | \lineiii{data} |
| 391 | {\filevar{#7}\filenq{#8}} |
Greg Ward | a021aca | 2000-04-19 22:34:11 +0000 | [diff] [blame] | 392 | {\longprogramopt{install-data}} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 393 | \end{tableiii}} |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 394 | |
Greg Ward | 0bc5953 | 2000-09-30 21:06:40 +0000 | [diff] [blame] | 395 | |
| 396 | \section{Building Extensions: Tips and Tricks} |
| 397 | \label{building-ext} |
| 398 | |
| 399 | (This is the section to read for people doing any sort of interesting |
| 400 | build. Things to talk about: |
| 401 | \begin{itemize} |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 402 | \item the \file{Setup} file (any platform now, but \UNIX-biased) |
Greg Ward | 0bc5953 | 2000-09-30 21:06:40 +0000 | [diff] [blame] | 403 | \item CFLAGS and LDFLAGS (must implement them first!) |
| 404 | \item using non-MS compilers on Windows (how to convert |
| 405 | Python's library, ...) |
| 406 | \end{itemize} |
| 407 | |
| 408 | |
| 409 | \subsection{Tweaking compiler/linker flags} |
| 410 | \label{tweak-flags} |
| 411 | |
| 412 | |
| 413 | \subsection{Using non-Microsoft compilers on Windows} |
| 414 | \label{non-ms-compilers} |
| 415 | |
| 416 | \XXX{One place to look: \url{http://www.cyberus.ca/~g_will/pyExtenDL.shtml}} |
| 417 | |
| 418 | |
| 419 | |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 420 | \section{Alternate Installation} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 421 | \label{alt-install} |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 422 | |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 423 | Often, it is necessary or desirable to install modules to a location |
| 424 | other than the standard location for third-party Python modules. For |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 425 | example, on a \UNIX{} system you might not have permission to write to the |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 426 | standard third-party module directory. Or you might wish to try out a |
| 427 | module before making it a standard part of your local Python |
| 428 | installation; this is especially true when upgrading a distribution |
| 429 | already present: you want to make sure your existing base of scripts |
| 430 | still works with the new version before actually upgrading. |
| 431 | |
| 432 | The Distutils \command{install} command is designed to make installing |
| 433 | module distributions to an alternate location simple and painless. The |
| 434 | basic idea is that you supply a base directory for the installation, and |
| 435 | the \command{install} command picks a set of directories (called an |
| 436 | \emph{installation scheme}) under this base directory in which to |
| 437 | install files. The details differ across platforms, so read whichever |
| 438 | of the following section applies to you. |
| 439 | |
| 440 | |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 441 | \subsection{Alternate installation: \UNIX{} (the home scheme)} |
Greg Ward | 1ed49ee | 2000-09-13 00:00:58 +0000 | [diff] [blame] | 442 | \label{alt-install-prefix} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 443 | |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 444 | Under \UNIX, there are two ways to perform an alternate installation. |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 445 | The ``prefix scheme'' is similar to how alternate installation works |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 446 | under Windows and MacOS, but is not necessarily the most useful way to |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 447 | maintain a personal Python library. Hence, we document the more |
| 448 | convenient and commonly useful ``home scheme'' first. |
| 449 | |
Greg Ward | c392caa | 2000-04-11 02:00:26 +0000 | [diff] [blame] | 450 | The idea behind the ``home scheme'' is that you build and maintain a |
| 451 | personal stash of Python modules, probably under your home directory. |
| 452 | Installing a new module distribution is as simple as |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 453 | \begin{verbatim} |
| 454 | python setup.py install --home=<dir> |
| 455 | \end{verbatim} |
Greg Ward | a021aca | 2000-04-19 22:34:11 +0000 | [diff] [blame] | 456 | where you can supply any directory you like for the \longprogramopt{home} |
Greg Ward | 4756e5f | 2000-04-19 22:40:12 +0000 | [diff] [blame] | 457 | option. Lazy typists can just type a tilde (\code{\textasciitilde}); the |
Greg Ward | c392caa | 2000-04-11 02:00:26 +0000 | [diff] [blame] | 458 | \command{install} command will expand this to your home directory: |
| 459 | \begin{verbatim} |
| 460 | python setup.py install --home=~ |
| 461 | \end{verbatim} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 462 | |
Greg Ward | 4eaa3bf | 2000-04-19 22:44:25 +0000 | [diff] [blame] | 463 | The \longprogramopt{home} option defines the installation base |
| 464 | directory. Files are installed to the following directories under the |
| 465 | installation base as follows: |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 466 | \installscheme{home}{/lib/python} |
| 467 | {home}{/lib/python} |
| 468 | {home}{/bin} |
| 469 | {home}{/share} |
| 470 | |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 471 | \subsection{Alternate installation: \UNIX{} (the prefix scheme)} |
Greg Ward | 1ed49ee | 2000-09-13 00:00:58 +0000 | [diff] [blame] | 472 | \label{alt-install-home} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 473 | |
| 474 | The ``prefix scheme'' is useful when you wish to use one Python |
| 475 | installation to perform the build/install (i.e., to run the setup |
| 476 | script), but install modules into the third-party module directory of a |
| 477 | different Python installation (or something that looks like a different |
| 478 | Python installation). If this sounds a trifle unusual, it is---that's |
| 479 | why the ``home scheme'' comes first. However, there are at least two |
| 480 | known cases where the prefix scheme will be useful. |
| 481 | |
Greg Ward | 19c67f8 | 2000-06-24 01:33:16 +0000 | [diff] [blame] | 482 | First, consider that many Linux distributions put Python in \file{/usr}, |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 483 | rather than the more traditional \file{/usr/local}. This is entirely |
| 484 | appropriate, since in those cases Python is part of ``the system'' |
| 485 | rather than a local add-on. However, if you are installing Python |
| 486 | modules from source, you probably want them to go in |
| 487 | \file{/usr/local/lib/python1.\filevar{X}} rather than |
| 488 | \file{/usr/lib/python1.\filevar{X}}. This can be done with |
| 489 | \begin{verbatim} |
| 490 | /usr/bin/python setup.py install --prefix=/usr/local |
| 491 | \end{verbatim} |
| 492 | |
| 493 | Another possibility is a network filesystem where the name used to write |
| 494 | to a remote directory is different from the name used to read it: for |
| 495 | example, the Python interpreter accessed as \file{/usr/local/bin/python} |
| 496 | might search for modules in \file{/usr/local/lib/python1.\filevar{X}}, |
| 497 | but those modules would have to be installed to, say, |
| 498 | \file{/mnt/\filevar{@server}/export/lib/python1.\filevar{X}}. This |
| 499 | could be done with |
| 500 | \begin{verbatim} |
| 501 | /usr/local/bin/python setup.py install --prefix=/mnt/@server/export |
| 502 | \end{verbatim} |
| 503 | |
Greg Ward | 4eaa3bf | 2000-04-19 22:44:25 +0000 | [diff] [blame] | 504 | In either case, the \longprogramopt{prefix} option defines the |
| 505 | installation base, and the \longprogramopt{exec-prefix} option defines |
| 506 | the platform-specific installation base, which is used for |
| 507 | platform-specific files. (Currently, this just means non-pure module |
| 508 | distributions, but could be expanded to C libraries, binary executables, |
| 509 | etc.) If \longprogramopt{exec-prefix} is not supplied, it defaults to |
| 510 | \longprogramopt{prefix}. Files are installed as follows: |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 511 | |
| 512 | \installscheme{prefix}{/lib/python1.\filevar{X}/site-packages} |
| 513 | {exec-prefix}{/lib/python1.\filevar{X}/site-packages} |
| 514 | {prefix}{/bin} |
| 515 | {prefix}{/share} |
| 516 | |
Greg Ward | 4eaa3bf | 2000-04-19 22:44:25 +0000 | [diff] [blame] | 517 | There is no requirement that \longprogramopt{prefix} or |
| 518 | \longprogramopt{exec-prefix} actually point to an alternate Python |
| 519 | installation; if the directories listed above do not already exist, they |
| 520 | are created at installation time. |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 521 | |
| 522 | Incidentally, the real reason the prefix scheme is important is simply |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 523 | that a standard \UNIX{} installation uses the prefix scheme, but with |
Greg Ward | 4eaa3bf | 2000-04-19 22:44:25 +0000 | [diff] [blame] | 524 | \longprogramopt{prefix} and \longprogramopt{exec-prefix} supplied by |
| 525 | Python itself (as \code{sys.prefix} and \code{sys.exec\_prefix}). Thus, |
| 526 | you might think you'll never use the prefix scheme, but every time you |
| 527 | run \code{python setup.py install} without any other options, you're |
| 528 | using it. |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 529 | |
| 530 | Note that installing extensions to an alternate Python installation has |
| 531 | no effect on how those extensions are built: in particular, the Python |
| 532 | header files (\file{Python.h} and friends) installed with the Python |
| 533 | interpreter used to run the setup script will be used in compiling |
| 534 | extensions. It is your responsibility to ensure that the interpreter |
| 535 | used to run extensions installed in this way is compatibile with the |
Greg Ward | c392caa | 2000-04-11 02:00:26 +0000 | [diff] [blame] | 536 | interpreter used to build them. The best way to do this is to ensure |
| 537 | that the two interpreters are the same version of Python (possibly |
| 538 | different builds, or possibly copies of the same build). (Of course, if |
Greg Ward | 4eaa3bf | 2000-04-19 22:44:25 +0000 | [diff] [blame] | 539 | your \longprogramopt{prefix} and \longprogramopt{exec-prefix} don't even |
| 540 | point to an alternate Python installation, this is immaterial.) |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 541 | |
| 542 | |
| 543 | \subsection{Alternate installation: Windows} |
Greg Ward | 1ed49ee | 2000-09-13 00:00:58 +0000 | [diff] [blame] | 544 | \label{alt-install-windows} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 545 | |
| 546 | Since Windows has no conception of a user's home directory, and since |
| 547 | the standard Python installation under Windows is simpler than that |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 548 | under \UNIX, there's no point in having separate \longprogramopt{prefix} |
Greg Ward | 4eaa3bf | 2000-04-19 22:44:25 +0000 | [diff] [blame] | 549 | and \longprogramopt{home} options. Just use the \longprogramopt{prefix} |
| 550 | option to specify a base directory, e.g. |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 551 | \begin{verbatim} |
Greg Ward | 8e14f05 | 2000-03-22 01:00:23 +0000 | [diff] [blame] | 552 | python setup.py install --prefix="\Temp\Python" |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 553 | \end{verbatim} |
Greg Ward | 4756e5f | 2000-04-19 22:40:12 +0000 | [diff] [blame] | 554 | to install modules to the \file{\textbackslash{}Temp} directory on the current |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 555 | drive. |
| 556 | |
Greg Ward | 4eaa3bf | 2000-04-19 22:44:25 +0000 | [diff] [blame] | 557 | The installation base is defined by the \longprogramopt{prefix} option; |
| 558 | the \longprogramopt{exec-prefix} option is not supported under Windows. |
| 559 | Files are installed as follows: |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 560 | \installscheme{prefix}{} |
| 561 | {prefix}{} |
Greg Ward | 4756e5f | 2000-04-19 22:40:12 +0000 | [diff] [blame] | 562 | {prefix}{\textbackslash{}Scripts} |
| 563 | {prefix}{\textbackslash{}Data} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 564 | |
| 565 | |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 566 | \subsection{Alternate installation: MacOS} |
Greg Ward | 1ed49ee | 2000-09-13 00:00:58 +0000 | [diff] [blame] | 567 | \label{alt-install-macos} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 568 | |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 569 | Like Windows, MacOS has no notion of home directories (or even of |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 570 | users), and a fairly simple standard Python installation. Thus, only a |
Greg Ward | 4eaa3bf | 2000-04-19 22:44:25 +0000 | [diff] [blame] | 571 | \longprogramopt{prefix} option is needed. It defines the installation |
| 572 | base, and files are installed under it as follows: |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 573 | |
Greg Ward | 8c56259 | 2000-09-13 00:12:37 +0000 | [diff] [blame] | 574 | \installscheme{prefix}{:Lib:site-packages} |
| 575 | {prefix}{:Lib:site-packages} |
Greg Ward | 8e14f05 | 2000-03-22 01:00:23 +0000 | [diff] [blame] | 576 | {prefix}{:Scripts} |
| 577 | {prefix}{:Data} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 578 | |
Greg Ward | 8c56259 | 2000-09-13 00:12:37 +0000 | [diff] [blame] | 579 | See section~\ref{platform-variations} for information on supplying |
| 580 | command-line arguments to the setup script with MacPython. |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 581 | |
| 582 | |
| 583 | \section{Custom Installation} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 584 | \label{custom-install} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 585 | |
| 586 | Sometimes, the alternate installation schemes described in |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 587 | section~\ref{alt-install} just don't do what you want. You might |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 588 | want to tweak just one or two directories while keeping everything under |
| 589 | the same base directory, or you might want to completely redefine the |
| 590 | installation scheme. In either case, you're creating a \emph{custom |
| 591 | installation scheme}. |
| 592 | |
| 593 | You probably noticed the column of ``override options'' in the tables |
| 594 | describing the alternate installation schemes above. Those options are |
| 595 | how you define a custom installation scheme. These override options can |
| 596 | be relative, absolute, or explicitly defined in terms of one of the |
| 597 | installation base directories. (There are two installation base |
| 598 | directories, and they are normally the same---they only differ when you |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 599 | use the \UNIX{} ``prefix scheme'' and supply different |
Greg Ward | 4eaa3bf | 2000-04-19 22:44:25 +0000 | [diff] [blame] | 600 | \longprogramopt{prefix} and \longprogramopt{exec-prefix} options.) |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 601 | |
| 602 | For example, say you're installing a module distribution to your home |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 603 | directory under \UNIX---but you want scripts to go in |
Greg Ward | 4eaa3bf | 2000-04-19 22:44:25 +0000 | [diff] [blame] | 604 | \file{\textasciitilde/scripts} rather than \file{\textasciitilde/bin}. |
| 605 | As you might expect, you can override this directory with the |
| 606 | \longprogramopt{install-scripts} option; in this case, it makes most |
| 607 | sense to supply a relative path, which will be interpreted relative to |
| 608 | the installation base directory (your home directory, in this case): |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 609 | \begin{verbatim} |
Greg Ward | 19c67f8 | 2000-06-24 01:33:16 +0000 | [diff] [blame] | 610 | python setup.py install --home=~ --install-scripts=scripts |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 611 | \end{verbatim} |
| 612 | |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 613 | Another \UNIX{} example: suppose your Python installation was built and |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 614 | installed with a prefix of \file{/usr/local/python}, so under a standard |
| 615 | installation scripts will wind up in \file{/usr/local/python/bin}. If |
| 616 | you want them in \file{/usr/local/bin} instead, you would supply this |
Greg Ward | a021aca | 2000-04-19 22:34:11 +0000 | [diff] [blame] | 617 | absolute directory for the \longprogramopt{install-scripts} option: |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 618 | \begin{verbatim} |
| 619 | python setup.py install --install-scripts=/usr/local/bin |
| 620 | \end{verbatim} |
| 621 | (This performs an installation using the ``prefix scheme,'' where the |
| 622 | prefix is whatever your Python interpreter was installed with--- |
| 623 | \file{/usr/local/python} in this case.) |
| 624 | |
| 625 | If you maintain Python on Windows, you might want third-party modules to |
| 626 | live in a subdirectory of \filevar{prefix}, rather than right in |
| 627 | \filevar{prefix} itself. This is almost as easy as customizing the |
| 628 | script installation directory---you just have to remember that there are |
| 629 | two types of modules to worry about, pure modules and non-pure modules |
| 630 | (i.e., modules from a non-pure distribution). For example: |
| 631 | \begin{verbatim} |
| 632 | python setup.py install --install-purelib=Site --install-platlib=Site |
| 633 | \end{verbatim} |
| 634 | The specified installation directories are relative to \filevar{prefix}. |
| 635 | Of course, you also have to ensure that these directories are in |
| 636 | 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] | 637 | \filevar{prefix} (\XXX{should have a section describing .pth files and |
| 638 | cross-ref it here}). |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 639 | |
| 640 | If you want to define an entire installation scheme, you just have to |
| 641 | supply all of the installation directory options. The recommended way |
Greg Ward | c392caa | 2000-04-11 02:00:26 +0000 | [diff] [blame] | 642 | to do this is to supply relative paths; for example, if you want to |
| 643 | maintain all Python module-related files under \file{python} in your |
| 644 | home directory, and you want a separate directory for each platform that |
| 645 | you use your home directory from, you might define the following |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 646 | installation scheme: |
| 647 | \begin{verbatim} |
Greg Ward | c392caa | 2000-04-11 02:00:26 +0000 | [diff] [blame] | 648 | python setup.py install --home=~ \ |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 649 | --install-purelib=python/lib \ |
| 650 | --install-platlib=python/lib.$PLAT \ |
| 651 | --install-scripts=python/scripts |
| 652 | --install-data=python/data |
| 653 | \end{verbatim} |
| 654 | or, equivalently, |
| 655 | \begin{verbatim} |
| 656 | python setup.py install --home=~/python \ |
| 657 | --install-purelib=lib \ |
Greg Ward | 19c67f8 | 2000-06-24 01:33:16 +0000 | [diff] [blame] | 658 | --install-platlib='lib.$PLAT' \ |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 659 | --install-scripts=scripts |
| 660 | --install-data=data |
| 661 | \end{verbatim} |
| 662 | \code{\$PLAT} is not (necessarily) an environment variable---it will be |
| 663 | expanded by the Distutils as it parses your command line options (just |
| 664 | as it does when parsing your configuration file(s)). |
| 665 | |
| 666 | Obviously, specifying the entire installation scheme every time you |
| 667 | install a new module distribution would be very tedious. Thus, you can |
| 668 | put these options into your Distutils config file (see |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 669 | section~\ref{config-files}): |
Greg Ward | 169f91b | 2000-03-10 01:57:51 +0000 | [diff] [blame] | 670 | \begin{verbatim} |
| 671 | [install] |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 672 | install-base=$HOME |
| 673 | install-purelib=python/lib |
| 674 | install-platlib=python/lib.$PLAT |
| 675 | install-scripts=python/scripts |
| 676 | install-data=python/data |
Greg Ward | 169f91b | 2000-03-10 01:57:51 +0000 | [diff] [blame] | 677 | \end{verbatim} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 678 | or, equivalently, |
Greg Ward | 169f91b | 2000-03-10 01:57:51 +0000 | [diff] [blame] | 679 | \begin{verbatim} |
| 680 | [install] |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 681 | install-base=$HOME/python |
| 682 | install-purelib=lib |
| 683 | install-platlib=lib.$PLAT |
| 684 | install-scripts=scripts |
| 685 | install-data=data |
Greg Ward | 169f91b | 2000-03-10 01:57:51 +0000 | [diff] [blame] | 686 | \end{verbatim} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 687 | Note that these two are \emph{not} equivalent if you supply a different |
| 688 | installation base directory when you run the setup script. For example, |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 689 | \begin{verbatim} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 690 | python setup.py --install-base=/tmp |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 691 | \end{verbatim} |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 692 | would install pure modules to \filevar{/tmp/python/lib} in the first |
| 693 | case, and to \filevar{/tmp/lib} in the second case. (For the second |
| 694 | case, you probably want to supply an installation base of |
| 695 | \file{/tmp/python}.) |
Greg Ward | 169f91b | 2000-03-10 01:57:51 +0000 | [diff] [blame] | 696 | |
Greg Ward | 2957656 | 2000-03-18 15:11:50 +0000 | [diff] [blame] | 697 | You probably noticed the use of \code{\$HOME} and \code{\$PLAT} in the |
| 698 | sample configuration file input. These are Distutils configuration |
| 699 | variables, which bear a strong resemblance to environment variables. In |
Greg Ward | c392caa | 2000-04-11 02:00:26 +0000 | [diff] [blame] | 700 | fact, you can use environment variables in config files---on platforms |
| 701 | that have such a notion---but the Distutils additionally define a few |
| 702 | extra variables that may not be in your environment, such as |
| 703 | \code{\$PLAT}. (And of course, you can only use the configuration |
| 704 | variables supplied by the Distutils on systems that don't have |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 705 | environment variables, such as MacOS (\XXX{true?}).) See |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 706 | section~\ref{config-files} for details. |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 707 | |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 708 | \XXX{need some Windows and MacOS examples---when would custom |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame] | 709 | installation schemes be needed on those platforms?} |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 710 | |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 711 | |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame] | 712 | \section{Distutils Configuration Files} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 713 | \label{config-files} |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 714 | |
Greg Ward | 7ef2ba7 | 2000-10-22 01:40:08 +0000 | [diff] [blame] | 715 | As mentioned above, you can use Distutils configuration files to record |
| 716 | personal or site preferences for any Distutils options. That is, any |
| 717 | option to any command can be stored in one of two or three (depending on |
| 718 | your platform) configuration files, which will be consulted before the |
| 719 | command-line is parsed. This means that configuration files will |
| 720 | override default values, and the command-line will in turn override |
| 721 | configuration files. Furthermore, if multiple configuration files |
| 722 | apply, values from ``earlier'' files are overridden by ``later'' files. |
| 723 | |
| 724 | |
| 725 | \subsection{Location and names of config files} |
Fred Drake | 0bbaa51 | 2001-01-24 16:39:35 +0000 | [diff] [blame^] | 726 | \label{config-filenames} |
Greg Ward | 7ef2ba7 | 2000-10-22 01:40:08 +0000 | [diff] [blame] | 727 | |
| 728 | The names and locations of the configuration files vary slightly across |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 729 | platforms. On \UNIX, the three configuration files (in the order they |
Greg Ward | 7ef2ba7 | 2000-10-22 01:40:08 +0000 | [diff] [blame] | 730 | are processed) are: |
| 731 | \begin{tableiii}{l|l|c}{textrm} |
| 732 | {Type of file}{Location and filename}{Notes} |
| 733 | \lineiii{system}{\filenq{\filevar{prefix}/lib/python\filevar{ver}/distutils/pydistutils.cfg}}{(1)} |
| 734 | \lineiii{personal}{\filenq{\$HOME/.pydistutils.cfg}}{(2)} |
| 735 | \lineiii{local}{\filenq{setup.cfg}}{(3)} |
| 736 | \end{tableiii} |
| 737 | |
| 738 | On Windows, the configuration files are: |
| 739 | \begin{tableiii}{l|l|c}{textrm} |
| 740 | {Type of file}{Location and filename}{Notes} |
| 741 | \lineiii{system}{\filenq{\filevar{prefix}\textbackslash{}Lib\textbackslash{}distutils\textbackslash{}pydistutils.cfg}}{(4)} |
| 742 | \lineiii{personal}{\filenq{\%HOME\textbackslash{}pydistutils.cfg}}{(5)} |
| 743 | \lineiii{local}{\filenq{setup.cfg}}{(3)} |
| 744 | \end{tableiii} |
| 745 | |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 746 | And on MacOS, they are: |
Greg Ward | 7ef2ba7 | 2000-10-22 01:40:08 +0000 | [diff] [blame] | 747 | \begin{tableiii}{l|l|c}{textrm} |
| 748 | {Type of file}{Location and filename}{Notes} |
| 749 | \lineiii{system}{\filenq{\filevar{prefix}:Lib:distutils:pydistutils.cfg}}{(6)} |
| 750 | \lineiii{personal}{N/A}{} |
| 751 | \lineiii{local}{\filenq{setup.cfg}}{(3)} |
| 752 | \end{tableiii} |
| 753 | |
| 754 | \noindent Notes: |
| 755 | \begin{description} |
| 756 | \item[(1)] Strictly speaking, the system-wide configuration file lives |
| 757 | in the directory where the Distutils are installed; under Python 1.6 |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 758 | and later on \UNIX, this is as shown. For Python 1.5.2, the Distutils |
Greg Ward | 7ef2ba7 | 2000-10-22 01:40:08 +0000 | [diff] [blame] | 759 | will normally be installed to |
| 760 | \file{\filevar{prefix}/lib/site-packages/python1.5/distutils}, |
| 761 | so the system configuration file should be put there under Python |
| 762 | 1.5.2. |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 763 | \item[(2)] On \UNIX, if the \envvar{HOME} environment variable is not |
Greg Ward | 7ef2ba7 | 2000-10-22 01:40:08 +0000 | [diff] [blame] | 764 | defined, the user's home directory will be determined with the |
| 765 | \function{getpwuid()} function from the standard \module{pwd} module. |
| 766 | \item[(3)] I.e., in the current directory (usually the location of the |
| 767 | setup script). |
| 768 | \item[(4)] (See also note (1).) Under Python 1.6 and later, Python's |
| 769 | default ``installation prefix'' is \file{C:\textbackslash{}Python}, so |
| 770 | the system configuration file is normally |
| 771 | \file{C:\textbackslash{}Python\textbackslash{}Lib\textbackslash{}distutils\textbackslash{}pydistutils.cfg}. |
| 772 | Under Python 1.5.2, the default prefix was |
| 773 | \file{C:\textbackslash{}Program~Files\textbackslash{}Python}, and the |
| 774 | Distutils were not part of the standard library---so the system |
| 775 | configuration file would be |
| 776 | \file{C:\textbackslash{}Program~Files\textbackslash{}Python\textbackslash{}distutils\textbackslash{}pydistutils.cfg} |
| 777 | in a standard Python 1.5.2 installation under Windows. |
| 778 | \item[(5)] On Windows, if the \envvar{HOME} environment variable is not |
| 779 | defined, no personal configuration file will be found or used. (In |
| 780 | other words, the Distutils make no attempt to guess your home |
| 781 | directory on Windows.) |
| 782 | \item[(6)] (See also notes (1) and (4).) The default installation |
| 783 | prefix is just \file{Python:}, so under Python 1.6 and later this is |
| 784 | normally\file{Python:Lib:distutils:pydistutils.cfg}. (The Distutils |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 785 | don't work very well with Python 1.5.2 under MacOS. \XXX{true?}) |
Greg Ward | 7ef2ba7 | 2000-10-22 01:40:08 +0000 | [diff] [blame] | 786 | \end{description} |
| 787 | |
| 788 | |
| 789 | \subsection{Syntax of config files} |
Fred Drake | 0bbaa51 | 2001-01-24 16:39:35 +0000 | [diff] [blame^] | 790 | \label{config-syntax} |
Greg Ward | 7ef2ba7 | 2000-10-22 01:40:08 +0000 | [diff] [blame] | 791 | |
| 792 | The Distutils configuration files all have the same syntax. The config |
| 793 | files are grouped into sections; there is one section for each Distutils |
| 794 | command, plus a \code{global} section for global options that affect |
| 795 | every command. Each section consists of one option per line, specified |
| 796 | like \code{option=value}. |
| 797 | |
| 798 | For example, the following is a complete config file that just forces |
| 799 | all commands to run quietly by default: |
| 800 | \begin{verbatim} |
| 801 | [global] |
| 802 | verbose=0 |
| 803 | \end{verbatim} |
| 804 | |
| 805 | If this is installed as the system config file, it will affect all |
| 806 | processing of any Python module distribution by any user on the current |
| 807 | system. If it is installed as your personal config file (on systems |
| 808 | that support them), it will affect only module distributions processed |
| 809 | by you. And if it is used as the \file{setup.cfg} for a particular |
| 810 | module distribution, it affects only that distribution. |
| 811 | |
| 812 | You could override the default ``build base'' directory and make the |
| 813 | \command{build*} commands always forcibly rebuild all files with the |
| 814 | following: |
| 815 | \begin{verbatim} |
| 816 | [build] |
| 817 | build-base=blib |
| 818 | force=1 |
| 819 | \end{verbatim} |
| 820 | which corresponds to the command-line arguments |
| 821 | \begin{verbatim} |
| 822 | python setup.py build --build-base=blib --force |
| 823 | \end{verbatim} |
| 824 | except that including the \command{build} command on the command-line |
| 825 | means that command will be run. Including a particular command in |
| 826 | config files has no such implication; it only means that if the command |
| 827 | is run, the options in the config file will apply. (Or if other |
| 828 | commands that derive values from it are run, they will use the values in |
| 829 | the config file.) |
| 830 | |
| 831 | You can find out the complete list of options for any command using the |
| 832 | \longprogramopt{help} option, e.g.: |
| 833 | \begin{verbatim} |
| 834 | python setup.py build --help |
| 835 | \end{verbatim} |
| 836 | and you can find out the complete list of global options by using |
| 837 | \longprogramopt{help} without a command: |
| 838 | \begin{verbatim} |
| 839 | python setup.py --help |
| 840 | \end{verbatim} |
| 841 | See also the ``Reference'' section of the ``Distributing Python |
| 842 | Modules'' manual. |
| 843 | |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame] | 844 | |
| 845 | \section{Pre-Distutils Conventions} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 846 | \label{pre-distutils} |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame] | 847 | |
| 848 | |
Greg Ward | c392caa | 2000-04-11 02:00:26 +0000 | [diff] [blame] | 849 | \subsection{The Makefile.pre.in file} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 850 | \label{makefile-pre-in} |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame] | 851 | |
| 852 | |
| 853 | \subsection{Installing modules manually} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 854 | \label{manual-install} |
Greg Ward | 6002ffc | 2000-04-09 20:54:50 +0000 | [diff] [blame] | 855 | |
| 856 | |
| 857 | |
Greg Ward | 7c1e5f6 | 2000-03-10 01:56:58 +0000 | [diff] [blame] | 858 | \end{document} |