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