blob: 893db1e9d4c1686f9d0819fe3198e00a30329ef1 [file] [log] [blame]
Georg Brandl8ec7f652007-08-15 14:28:01 +00001.. highlightlang:: none
2
3.. _install-index:
4
5*****************************
Georg Brandlc62ef8b2009-01-03 20:55:06 +00006 Installing Python Modules
Georg Brandl8ec7f652007-08-15 14:28:01 +00007*****************************
8
9:Author: Greg Ward
Georg Brandl8ec7f652007-08-15 14:28:01 +000010
Georg Brandlb19be572007-12-29 10:57:00 +000011.. TODO: Fill in XXX comments
Georg Brandl8ec7f652007-08-15 14:28:01 +000012
Georg Brandlb19be572007-12-29 10:57:00 +000013.. The audience for this document includes people who don't know anything
14 about Python and aren't about to learn the language just in order to
15 install and maintain it for their users, i.e. system administrators.
16 Thus, I have to be sure to explain the basics at some point:
17 sys.path and PYTHONPATH at least. Should probably give pointers to
18 other docs on "import site", PYTHONSTARTUP, PYTHONHOME, etc.
Georg Brandlc62ef8b2009-01-03 20:55:06 +000019
Georg Brandlb19be572007-12-29 10:57:00 +000020 Finally, it might be useful to include all the material from my "Care
21 and Feeding of a Python Installation" talk in here somewhere. Yow!
Georg Brandl8ec7f652007-08-15 14:28:01 +000022
Nick Coghlan73188fb2013-12-10 21:18:32 +100023This document describes the Python Distribution Utilities ("Distutils") from the
24end-user's point-of-view, describing how to extend the capabilities of a
25standard Python installation by building and installing third-party Python
26modules and extensions.
Georg Brandl8ec7f652007-08-15 14:28:01 +000027
Nick Coghlan73188fb2013-12-10 21:18:32 +100028
29.. note::
Benjamin Petersonbe038072015-11-03 22:43:31 -080030
Benjamin Peterson873cad22015-11-03 22:42:02 -080031 This guide only covers the basic tools for building and distributing
32 extensions that are provided as part of this version of Python. Third party
33 tools offer easier to use and more secure alternatives. Refer to the `quick
34 recommendations section <https://packaging.python.org/en/latest/current/>`__
Nick Coghlan73188fb2013-12-10 21:18:32 +100035 in the Python Packaging User Guide for more information.
Georg Brandl8ec7f652007-08-15 14:28:01 +000036
37
38.. _inst-intro:
39
Benjamin Peterson873cad22015-11-03 22:42:02 -080040
Georg Brandl8ec7f652007-08-15 14:28:01 +000041Introduction
42============
43
44Although Python's extensive standard library covers many programming needs,
45there often comes a time when you need to add some new functionality to your
46Python installation in the form of third-party modules. This might be necessary
47to support your own programming, or to support an application that you want to
48use and that happens to be written in Python.
49
50In the past, there has been little support for adding third-party modules to an
51existing Python installation. With the introduction of the Python Distribution
52Utilities (Distutils for short) in Python 2.0, this changed.
53
54This document is aimed primarily at the people who need to install third-party
55Python modules: end-users and system administrators who just need to get some
56Python application running, and existing Python programmers who want to add some
57new goodies to their toolbox. You don't need to know Python to read this
58document; there will be some brief forays into using Python's interactive mode
59to explore your installation, but that's it. If you're looking for information
60on how to distribute your own Python modules so that others may use them, see
Éric Araujo31fe52d2014-03-12 22:19:39 -040061the :ref:`distutils-index` manual. :ref:`debug-setup-script` may also be of
62interest.
63
Georg Brandl8ec7f652007-08-15 14:28:01 +000064
65
66.. _inst-trivial-install:
67
68Best case: trivial installation
69-------------------------------
70
71In the best case, someone will have prepared a special version of the module
72distribution you want to install that is targeted specifically at your platform
73and is installed just like any other software on your platform. For example,
74the module developer might make an executable installer available for Windows
75users, an RPM package for users of RPM-based Linux systems (Red Hat, SuSE,
76Mandrake, and many others), a Debian package for users of Debian-based Linux
77systems, and so forth.
78
79In that case, you would download the installer appropriate to your platform and
80do the obvious thing with it: run it if it's an executable installer, ``rpm
81--install`` it if it's an RPM, etc. You don't need to run Python or a setup
82script, you don't need to compile anything---you might not even need to read any
Éric Araujo2e1c2942011-07-29 11:57:50 +020083instructions (although it's always a good idea to do so anyway).
Georg Brandl8ec7f652007-08-15 14:28:01 +000084
85Of course, things will not always be that easy. You might be interested in a
86module distribution that doesn't have an easy-to-use installer for your
87platform. In that case, you'll have to start with the source distribution
88released by the module's author/maintainer. Installing from a source
89distribution is not too hard, as long as the modules are packaged in the
90standard way. The bulk of this document is about building and installing
91modules from standard source distributions.
92
93
94.. _inst-new-standard:
95
96The new standard: Distutils
97---------------------------
98
99If you download a module source distribution, you can tell pretty quickly if it
100was packaged and distributed in the standard way, i.e. using the Distutils.
101First, the distribution's name and version number will be featured prominently
102in the name of the downloaded archive, e.g. :file:`foo-1.0.tar.gz` or
103:file:`widget-0.9.7.zip`. Next, the archive will unpack into a similarly-named
104directory: :file:`foo-1.0` or :file:`widget-0.9.7`. Additionally, the
105distribution will contain a setup script :file:`setup.py`, and a file named
106:file:`README.txt` or possibly just :file:`README`, which should explain that
Éric Araujoa65a8802011-06-08 01:11:36 +0200107building and installing the module distribution is a simple matter of running
108one command from a terminal::
Georg Brandl8ec7f652007-08-15 14:28:01 +0000109
110 python setup.py install
111
Éric Araujoa2596a42011-08-19 09:29:56 +0200112For Windows, this command should be run from a command prompt window
113(:menuselection:`Start --> Accessories`)::
Éric Araujoa65a8802011-06-08 01:11:36 +0200114
115 setup.py install
116
Georg Brandl8ec7f652007-08-15 14:28:01 +0000117If all these things are true, then you already know how to build and install the
118modules you've just downloaded: Run the command above. Unless you need to
119install things in a non-standard way or customize the build process, you don't
120really need this manual. Or rather, the above command is everything you need to
121get out of this manual.
122
123
124.. _inst-standard-install:
125
126Standard Build and Install
127==========================
128
129As described in section :ref:`inst-new-standard`, building and installing a module
Éric Araujoa65a8802011-06-08 01:11:36 +0200130distribution using the Distutils is usually one simple command to run from a
131terminal::
Georg Brandl8ec7f652007-08-15 14:28:01 +0000132
133 python setup.py install
134
Georg Brandl8ec7f652007-08-15 14:28:01 +0000135
136.. _inst-platform-variations:
137
138Platform variations
139-------------------
140
141You should always run the setup command from the distribution root directory,
142i.e. the top-level subdirectory that the module source distribution unpacks
143into. For example, if you've just downloaded a module source distribution
144:file:`foo-1.0.tar.gz` onto a Unix system, the normal thing to do is::
145
146 gunzip -c foo-1.0.tar.gz | tar xf - # unpacks into directory foo-1.0
147 cd foo-1.0
148 python setup.py install
149
150On Windows, you'd probably download :file:`foo-1.0.zip`. If you downloaded the
151archive file to :file:`C:\\Temp`, then it would unpack into
Serhiy Storchakac72e66a2015-11-02 15:06:09 +0200152:file:`C:\\Temp\\foo-1.0`; you can use either an archive manipulator with a
Georg Brandl8ec7f652007-08-15 14:28:01 +0000153graphical user interface (such as WinZip) or a command-line tool (such as
154:program:`unzip` or :program:`pkunzip`) to unpack the archive. Then, open a
Éric Araujoa2596a42011-08-19 09:29:56 +0200155command prompt window and run::
Georg Brandl8ec7f652007-08-15 14:28:01 +0000156
157 cd c:\Temp\foo-1.0
158 python setup.py install
159
160
161.. _inst-splitting-up:
162
163Splitting the job up
164--------------------
165
166Running ``setup.py install`` builds and installs all modules in one run. If you
167prefer to work incrementally---especially useful if you want to customize the
168build process, or if things are going wrong---you can use the setup script to do
169one thing at a time. This is particularly helpful when the build and install
170will be done by different users---for example, you might want to build a module
171distribution and hand it off to a system administrator for installation (or do
172it yourself, with super-user privileges).
173
174For example, you can build everything in one step, and then install everything
175in a second step, by invoking the setup script twice::
176
177 python setup.py build
178 python setup.py install
179
180If you do this, you will notice that running the :command:`install` command
181first runs the :command:`build` command, which---in this case---quickly notices
182that it has nothing to do, since everything in the :file:`build` directory is
183up-to-date.
184
185You may not need this ability to break things down often if all you do is
186install modules downloaded off the 'net, but it's very handy for more advanced
187tasks. If you get into distributing your own Python modules and extensions,
188you'll run lots of individual Distutils commands on their own.
189
190
191.. _inst-how-build-works:
192
193How building works
194------------------
195
196As implied above, the :command:`build` command is responsible for putting the
197files to install into a *build directory*. By default, this is :file:`build`
198under the distribution root; if you're excessively concerned with speed, or want
199to keep the source tree pristine, you can change the build directory with the
200:option:`--build-base` option. For example::
201
Petri Lehtinen0b785032013-02-23 19:24:08 +0100202 python setup.py build --build-base=/path/to/pybuild/foo-1.0
Georg Brandl8ec7f652007-08-15 14:28:01 +0000203
204(Or you could do this permanently with a directive in your system or personal
205Distutils configuration file; see section :ref:`inst-config-files`.) Normally, this
206isn't necessary.
207
208The default layout for the build tree is as follows::
209
210 --- build/ --- lib/
211 or
212 --- build/ --- lib.<plat>/
213 temp.<plat>/
214
215where ``<plat>`` expands to a brief description of the current OS/hardware
216platform and Python version. The first form, with just a :file:`lib` directory,
217is used for "pure module distributions"---that is, module distributions that
218include only pure Python modules. If a module distribution contains any
219extensions (modules written in C/C++), then the second form, with two ``<plat>``
220directories, is used. In that case, the :file:`temp.{plat}` directory holds
221temporary files generated by the compile/link process that don't actually get
222installed. In either case, the :file:`lib` (or :file:`lib.{plat}`) directory
223contains all Python modules (pure Python and extensions) that will be installed.
224
225In the future, more directories will be added to handle Python scripts,
226documentation, binary executables, and whatever else is needed to handle the job
227of installing Python modules and applications.
228
229
230.. _inst-how-install-works:
231
232How installation works
233----------------------
234
235After the :command:`build` command runs (whether you run it explicitly, or the
236:command:`install` command does it for you), the work of the :command:`install`
237command is relatively simple: all it has to do is copy everything under
238:file:`build/lib` (or :file:`build/lib.{plat}`) to your chosen installation
239directory.
240
241If you don't choose an installation directory---i.e., if you just run ``setup.py
242install``\ ---then the :command:`install` command installs to the standard
243location for third-party Python modules. This location varies by platform and
244by how you built/installed Python itself. On Unix (and Mac OS X, which is also
245Unix-based), it also depends on whether the module distribution being installed
246is pure Python or contains extensions ("non-pure"):
247
Georg Brandl44ea77b2013-03-28 13:28:44 +0100248.. tabularcolumns:: |l|l|l|l|
249
Georg Brandl8ec7f652007-08-15 14:28:01 +0000250+-----------------+-----------------------------------------------------+--------------------------------------------------+-------+
251| Platform | Standard installation location | Default value | Notes |
252+=================+=====================================================+==================================================+=======+
253| Unix (pure) | :file:`{prefix}/lib/python{X.Y}/site-packages` | :file:`/usr/local/lib/python{X.Y}/site-packages` | \(1) |
254+-----------------+-----------------------------------------------------+--------------------------------------------------+-------+
255| Unix (non-pure) | :file:`{exec-prefix}/lib/python{X.Y}/site-packages` | :file:`/usr/local/lib/python{X.Y}/site-packages` | \(1) |
256+-----------------+-----------------------------------------------------+--------------------------------------------------+-------+
Brian Curtin1602ec12011-05-03 22:01:53 -0500257| Windows | :file:`{prefix}\\Lib\\site-packages` | :file:`C:\\Python{XY}\\Lib\\site-packages` | \(2) |
Georg Brandl8ec7f652007-08-15 14:28:01 +0000258+-----------------+-----------------------------------------------------+--------------------------------------------------+-------+
259
260Notes:
261
262(1)
263 Most Linux distributions include Python as a standard part of the system, so
264 :file:`{prefix}` and :file:`{exec-prefix}` are usually both :file:`/usr` on
265 Linux. If you build Python yourself on Linux (or any Unix-like system), the
266 default :file:`{prefix}` and :file:`{exec-prefix}` are :file:`/usr/local`.
267
268(2)
269 The default installation directory on Windows was :file:`C:\\Program
270 Files\\Python` under Python 1.6a1, 1.5.2, and earlier.
271
272:file:`{prefix}` and :file:`{exec-prefix}` stand for the directories that Python
273is installed to, and where it finds its libraries at run-time. They are always
274the same under Windows, and very often the same under Unix and Mac OS X. You
275can find out what your Python installation uses for :file:`{prefix}` and
276:file:`{exec-prefix}` by running Python in interactive mode and typing a few
277simple commands. Under Unix, just type ``python`` at the shell prompt. Under
278Windows, choose :menuselection:`Start --> Programs --> Python X.Y -->
279Python (command line)`. Once the interpreter is started, you type Python code
280at the prompt. For example, on my Linux system, I type the three Python
281statements shown below, and get the output as shown, to find out my
282:file:`{prefix}` and :file:`{exec-prefix}`::
283
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000284 Python 2.4 (#26, Aug 7 2004, 17:19:02)
Georg Brandl8ec7f652007-08-15 14:28:01 +0000285 Type "help", "copyright", "credits" or "license" for more information.
286 >>> import sys
287 >>> sys.prefix
288 '/usr'
289 >>> sys.exec_prefix
290 '/usr'
291
Éric Araujoe68d4502011-08-19 08:34:52 +0200292A few other placeholders are used in this document: :file:`{X.Y}` stands for the
293version of Python, for example ``2.7``; :file:`{distname}` will be replaced by
294the name of the module distribution being installed. Dots and capitalization
295are important in the paths; for example, a value that uses ``python2.7`` on UNIX
296will typically use ``Python27`` on Windows.
297
Georg Brandl8ec7f652007-08-15 14:28:01 +0000298If you don't want to install modules to the standard location, or if you don't
299have permission to write there, then you need to read about alternate
300installations in section :ref:`inst-alt-install`. If you want to customize your
301installation directories more heavily, see section :ref:`inst-custom-install` on
302custom installations.
303
304
305.. _inst-alt-install:
306
307Alternate Installation
308======================
309
310Often, it is necessary or desirable to install modules to a location other than
311the standard location for third-party Python modules. For example, on a Unix
312system you might not have permission to write to the standard third-party module
313directory. Or you might wish to try out a module before making it a standard
314part of your local Python installation. This is especially true when upgrading
315a distribution already present: you want to make sure your existing base of
316scripts still works with the new version before actually upgrading.
317
318The Distutils :command:`install` command is designed to make installing module
319distributions to an alternate location simple and painless. The basic idea is
320that you supply a base directory for the installation, and the
321:command:`install` command picks a set of directories (called an *installation
322scheme*) under this base directory in which to install files. The details
323differ across platforms, so read whichever of the following sections applies to
324you.
325
Éric Araujoe68d4502011-08-19 08:34:52 +0200326Note that the various alternate installation schemes are mutually exclusive: you
327can pass ``--user``, or ``--home``, or ``--prefix`` and ``--exec-prefix``, or
328``--install-base`` and ``--install-platbase``, but you can't mix from these
329groups.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000330
Éric Araujoe68d4502011-08-19 08:34:52 +0200331
332.. _inst-alt-install-user:
333
334Alternate installation: the user scheme
335---------------------------------------
336
337This scheme is designed to be the most convenient solution for users that don't
338have write permission to the global site-packages directory or don't want to
339install into it. It is enabled with a simple option::
340
341 python setup.py install --user
342
343Files will be installed into subdirectories of :data:`site.USER_BASE` (written
344as :file:`{userbase}` hereafter). This scheme installs pure Python modules and
345extension modules in the same location (also known as :data:`site.USER_SITE`).
346Here are the values for UNIX, including Mac OS X:
347
348=============== ===========================================================
349Type of file Installation directory
350=============== ===========================================================
351modules :file:`{userbase}/lib/python{X.Y}/site-packages`
352scripts :file:`{userbase}/bin`
353data :file:`{userbase}`
354C headers :file:`{userbase}/include/python{X.Y}/{distname}`
355=============== ===========================================================
356
357And here are the values used on Windows:
358
359=============== ===========================================================
360Type of file Installation directory
361=============== ===========================================================
362modules :file:`{userbase}\\Python{XY}\\site-packages`
363scripts :file:`{userbase}\\Scripts`
364data :file:`{userbase}`
365C headers :file:`{userbase}\\Python{XY}\\Include\\{distname}`
366=============== ===========================================================
367
368The advantage of using this scheme compared to the other ones described below is
369that the user site-packages directory is under normal conditions always included
370in :data:`sys.path` (see :mod:`site` for more information), which means that
371there is no additional step to perform after running the :file:`setup.py` script
372to finalize the installation.
373
374The :command:`build_ext` command also has a ``--user`` option to add
375:file:`{userbase}/include` to the compiler search path for header files and
376:file:`{userbase}/lib` to the compiler search path for libraries as well as to
377the runtime search path for shared C libraries (rpath).
378
379
380.. _inst-alt-install-home:
Georg Brandl8ec7f652007-08-15 14:28:01 +0000381
382Alternate installation: the home scheme
383---------------------------------------
384
385The idea behind the "home scheme" is that you build and maintain a personal
386stash of Python modules. This scheme's name is derived from the idea of a
387"home" directory on Unix, since it's not unusual for a Unix user to make their
388home directory have a layout similar to :file:`/usr/` or :file:`/usr/local/`.
Georg Brandl8891e232010-08-01 21:23:50 +0000389This scheme can be used by anyone, regardless of the operating system they
390are installing for.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000391
392Installing a new module distribution is as simple as ::
393
394 python setup.py install --home=<dir>
395
396where you can supply any directory you like for the :option:`--home` option. On
397Unix, lazy typists can just type a tilde (``~``); the :command:`install` command
398will expand this to your home directory::
399
400 python setup.py install --home=~
401
Éric Araujoe68d4502011-08-19 08:34:52 +0200402To make Python find the distributions installed with this scheme, you may have
403to :ref:`modify Python's search path <inst-search-path>` or edit
404:mod:`sitecustomize` (see :mod:`site`) to call :func:`site.addsitedir` or edit
405:data:`sys.path`.
406
Georg Brandl8ec7f652007-08-15 14:28:01 +0000407The :option:`--home` option defines the installation base directory. Files are
408installed to the following directories under the installation base as follows:
409
Éric Araujoe68d4502011-08-19 08:34:52 +0200410=============== ===========================================================
411Type of file Installation directory
412=============== ===========================================================
413modules :file:`{home}/lib/python`
414scripts :file:`{home}/bin`
415data :file:`{home}`
416C headers :file:`{home}/include/python/{distname}`
417=============== ===========================================================
418
419(Mentally replace slashes with backslashes if you're on Windows.)
Georg Brandl8ec7f652007-08-15 14:28:01 +0000420
421.. versionchanged:: 2.4
422 The :option:`--home` option used to be supported only on Unix.
423
424
Éric Araujoe68d4502011-08-19 08:34:52 +0200425.. _inst-alt-install-prefix-unix:
Georg Brandl8ec7f652007-08-15 14:28:01 +0000426
427Alternate installation: Unix (the prefix scheme)
428------------------------------------------------
429
430The "prefix scheme" is useful when you wish to use one Python installation to
431perform the build/install (i.e., to run the setup script), but install modules
432into the third-party module directory of a different Python installation (or
433something that looks like a different Python installation). If this sounds a
Éric Araujoe68d4502011-08-19 08:34:52 +0200434trifle unusual, it is---that's why the user and home schemes come before. However,
Georg Brandl8ec7f652007-08-15 14:28:01 +0000435there are at least two known cases where the prefix scheme will be useful.
436
437First, consider that many Linux distributions put Python in :file:`/usr`, rather
438than the more traditional :file:`/usr/local`. This is entirely appropriate,
439since in those cases Python is part of "the system" rather than a local add-on.
440However, if you are installing Python modules from source, you probably want
441them to go in :file:`/usr/local/lib/python2.{X}` rather than
442:file:`/usr/lib/python2.{X}`. This can be done with ::
443
444 /usr/bin/python setup.py install --prefix=/usr/local
445
446Another possibility is a network filesystem where the name used to write to a
447remote directory is different from the name used to read it: for example, the
448Python interpreter accessed as :file:`/usr/local/bin/python` might search for
449modules in :file:`/usr/local/lib/python2.{X}`, but those modules would have to
450be installed to, say, :file:`/mnt/{@server}/export/lib/python2.{X}`. This could
451be done with ::
452
453 /usr/local/bin/python setup.py install --prefix=/mnt/@server/export
454
455In either case, the :option:`--prefix` option defines the installation base, and
456the :option:`--exec-prefix` option defines the platform-specific installation
457base, which is used for platform-specific files. (Currently, this just means
458non-pure module distributions, but could be expanded to C libraries, binary
459executables, etc.) If :option:`--exec-prefix` is not supplied, it defaults to
460:option:`--prefix`. Files are installed as follows:
461
Éric Araujoe68d4502011-08-19 08:34:52 +0200462================= ==========================================================
463Type of file Installation directory
464================= ==========================================================
465Python modules :file:`{prefix}/lib/python{X.Y}/site-packages`
466extension modules :file:`{exec-prefix}/lib/python{X.Y}/site-packages`
467scripts :file:`{prefix}/bin`
468data :file:`{prefix}`
469C headers :file:`{prefix}/include/python{X.Y}/{distname}`
470================= ==========================================================
Georg Brandl8ec7f652007-08-15 14:28:01 +0000471
472There is no requirement that :option:`--prefix` or :option:`--exec-prefix`
473actually point to an alternate Python installation; if the directories listed
474above do not already exist, they are created at installation time.
475
476Incidentally, the real reason the prefix scheme is important is simply that a
477standard Unix installation uses the prefix scheme, but with :option:`--prefix`
478and :option:`--exec-prefix` supplied by Python itself as ``sys.prefix`` and
479``sys.exec_prefix``. Thus, you might think you'll never use the prefix scheme,
480but every time you run ``python setup.py install`` without any other options,
481you're using it.
482
483Note that installing extensions to an alternate Python installation has no
484effect on how those extensions are built: in particular, the Python header files
485(:file:`Python.h` and friends) installed with the Python interpreter used to run
486the setup script will be used in compiling extensions. It is your
487responsibility to ensure that the interpreter used to run extensions installed
488in this way is compatible with the interpreter used to build them. The best way
489to do this is to ensure that the two interpreters are the same version of Python
490(possibly different builds, or possibly copies of the same build). (Of course,
491if your :option:`--prefix` and :option:`--exec-prefix` don't even point to an
492alternate Python installation, this is immaterial.)
493
494
Éric Araujoe68d4502011-08-19 08:34:52 +0200495.. _inst-alt-install-prefix-windows:
Georg Brandl8ec7f652007-08-15 14:28:01 +0000496
497Alternate installation: Windows (the prefix scheme)
498---------------------------------------------------
499
500Windows has no concept of a user's home directory, and since the standard Python
501installation under Windows is simpler than under Unix, the :option:`--prefix`
502option has traditionally been used to install additional packages in separate
503locations on Windows. ::
504
505 python setup.py install --prefix="\Temp\Python"
506
507to install modules to the :file:`\\Temp\\Python` directory on the current drive.
508
509The installation base is defined by the :option:`--prefix` option; the
Éric Araujoe68d4502011-08-19 08:34:52 +0200510:option:`--exec-prefix` option is not supported under Windows, which means that
511pure Python modules and extension modules are installed into the same location.
512Files are installed as follows:
Georg Brandl8ec7f652007-08-15 14:28:01 +0000513
Éric Araujoe68d4502011-08-19 08:34:52 +0200514=============== ==========================================================
515Type of file Installation directory
516=============== ==========================================================
517modules :file:`{prefix}\\Lib\\site-packages`
518scripts :file:`{prefix}\\Scripts`
519data :file:`{prefix}`
520C headers :file:`{prefix}\\Include\\{distname}`
521=============== ==========================================================
Georg Brandl8ec7f652007-08-15 14:28:01 +0000522
523
524.. _inst-custom-install:
525
526Custom Installation
527===================
528
529Sometimes, the alternate installation schemes described in section
530:ref:`inst-alt-install` just don't do what you want. You might want to tweak just
531one or two directories while keeping everything under the same base directory,
532or you might want to completely redefine the installation scheme. In either
533case, you're creating a *custom installation scheme*.
534
Éric Araujoe68d4502011-08-19 08:34:52 +0200535To create a custom installation scheme, you start with one of the alternate
536schemes and override some of the installation directories used for the various
537types of files, using these options:
538
539====================== =======================
540Type of file Override option
541====================== =======================
542Python modules ``--install-purelib``
543extension modules ``--install-platlib``
544all modules ``--install-lib``
545scripts ``--install-scripts``
546data ``--install-data``
547C headers ``--install-headers``
548====================== =======================
549
550These override options can be relative, absolute,
Georg Brandl8ec7f652007-08-15 14:28:01 +0000551or explicitly defined in terms of one of the installation base directories.
552(There are two installation base directories, and they are normally the same---
553they only differ when you use the Unix "prefix scheme" and supply different
Éric Araujoe68d4502011-08-19 08:34:52 +0200554``--prefix`` and ``--exec-prefix`` options; using ``--install-lib`` will
555override values computed or given for ``--install-purelib`` and
556``--install-platlib``, and is recommended for schemes that don't make a
557difference between Python and extension modules.)
Georg Brandl8ec7f652007-08-15 14:28:01 +0000558
559For example, say you're installing a module distribution to your home directory
560under Unix---but you want scripts to go in :file:`~/scripts` rather than
561:file:`~/bin`. As you might expect, you can override this directory with the
562:option:`--install-scripts` option; in this case, it makes most sense to supply
563a relative path, which will be interpreted relative to the installation base
564directory (your home directory, in this case)::
565
566 python setup.py install --home=~ --install-scripts=scripts
567
568Another Unix example: suppose your Python installation was built and installed
569with a prefix of :file:`/usr/local/python`, so under a standard installation
570scripts will wind up in :file:`/usr/local/python/bin`. If you want them in
571:file:`/usr/local/bin` instead, you would supply this absolute directory for the
572:option:`--install-scripts` option::
573
574 python setup.py install --install-scripts=/usr/local/bin
575
576(This performs an installation using the "prefix scheme," where the prefix is
577whatever your Python interpreter was installed with--- :file:`/usr/local/python`
578in this case.)
579
580If you maintain Python on Windows, you might want third-party modules to live in
581a subdirectory of :file:`{prefix}`, rather than right in :file:`{prefix}`
582itself. This is almost as easy as customizing the script installation directory
583---you just have to remember that there are two types of modules to worry about,
Éric Araujoe68d4502011-08-19 08:34:52 +0200584Python and extension modules, which can conveniently be both controlled by one
585option::
Georg Brandl8ec7f652007-08-15 14:28:01 +0000586
Éric Araujoe68d4502011-08-19 08:34:52 +0200587 python setup.py install --install-lib=Site
Georg Brandl8ec7f652007-08-15 14:28:01 +0000588
Éric Araujoe68d4502011-08-19 08:34:52 +0200589The specified installation directory is relative to :file:`{prefix}`. Of
590course, you also have to ensure that this directory is in Python's module
591search path, such as by putting a :file:`.pth` file in a site directory (see
592:mod:`site`). See section :ref:`inst-search-path` to find out how to modify
593Python's search path.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000594
595If you want to define an entire installation scheme, you just have to supply all
596of the installation directory options. The recommended way to do this is to
597supply relative paths; for example, if you want to maintain all Python
598module-related files under :file:`python` in your home directory, and you want a
599separate directory for each platform that you use your home directory from, you
600might define the following installation scheme::
601
602 python setup.py install --home=~ \
603 --install-purelib=python/lib \
604 --install-platlib=python/lib.$PLAT \
605 --install-scripts=python/scripts
606 --install-data=python/data
607
Georg Brandlb19be572007-12-29 10:57:00 +0000608or, equivalently, ::
Georg Brandl8ec7f652007-08-15 14:28:01 +0000609
610 python setup.py install --home=~/python \
611 --install-purelib=lib \
612 --install-platlib='lib.$PLAT' \
613 --install-scripts=scripts
614 --install-data=data
615
616``$PLAT`` is not (necessarily) an environment variable---it will be expanded by
617the Distutils as it parses your command line options, just as it does when
618parsing your configuration file(s).
619
Georg Brandl8ec7f652007-08-15 14:28:01 +0000620Obviously, specifying the entire installation scheme every time you install a
621new module distribution would be very tedious. Thus, you can put these options
622into your Distutils config file (see section :ref:`inst-config-files`)::
623
624 [install]
625 install-base=$HOME
626 install-purelib=python/lib
627 install-platlib=python/lib.$PLAT
628 install-scripts=python/scripts
629 install-data=python/data
630
631or, equivalently, ::
632
633 [install]
634 install-base=$HOME/python
635 install-purelib=lib
636 install-platlib=lib.$PLAT
637 install-scripts=scripts
638 install-data=data
639
640Note that these two are *not* equivalent if you supply a different installation
641base directory when you run the setup script. For example, ::
642
643 python setup.py install --install-base=/tmp
644
Éric Araujoe68d4502011-08-19 08:34:52 +0200645would install pure modules to :file:`/tmp/python/lib` in the first case, and
646to :file:`/tmp/lib` in the second case. (For the second case, you probably
Georg Brandl8ec7f652007-08-15 14:28:01 +0000647want to supply an installation base of :file:`/tmp/python`.)
648
649You probably noticed the use of ``$HOME`` and ``$PLAT`` in the sample
650configuration file input. These are Distutils configuration variables, which
651bear a strong resemblance to environment variables. In fact, you can use
652environment variables in config files on platforms that have such a notion but
653the Distutils additionally define a few extra variables that may not be in your
654environment, such as ``$PLAT``. (And of course, on systems that don't have
655environment variables, such as Mac OS 9, the configuration variables supplied by
656the Distutils are the only ones you can use.) See section :ref:`inst-config-files`
657for details.
658
Georg Brandlb19be572007-12-29 10:57:00 +0000659.. XXX need some Windows examples---when would custom installation schemes be
660 needed on those platforms?
Georg Brandl8ec7f652007-08-15 14:28:01 +0000661
Georg Brandl8ec7f652007-08-15 14:28:01 +0000662
Éric Araujoe68d4502011-08-19 08:34:52 +0200663.. XXX Move this to Doc/using
Georg Brandl8ec7f652007-08-15 14:28:01 +0000664
665.. _inst-search-path:
666
667Modifying Python's Search Path
668------------------------------
669
670When the Python interpreter executes an :keyword:`import` statement, it searches
671for both Python code and extension modules along a search path. A default value
672for the path is configured into the Python binary when the interpreter is built.
673You can determine the path by importing the :mod:`sys` module and printing the
674value of ``sys.path``. ::
675
676 $ python
677 Python 2.2 (#11, Oct 3 2002, 13:31:27)
678 [GCC 2.96 20000731 (Red Hat Linux 7.3 2.96-112)] on linux2
Georg Brandlfc29f272009-01-02 20:25:14 +0000679 Type "help", "copyright", "credits" or "license" for more information.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000680 >>> import sys
681 >>> sys.path
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000682 ['', '/usr/local/lib/python2.3', '/usr/local/lib/python2.3/plat-linux2',
683 '/usr/local/lib/python2.3/lib-tk', '/usr/local/lib/python2.3/lib-dynload',
Georg Brandl8ec7f652007-08-15 14:28:01 +0000684 '/usr/local/lib/python2.3/site-packages']
685 >>>
686
687The null string in ``sys.path`` represents the current working directory.
688
Georg Brandl8ec7f652007-08-15 14:28:01 +0000689The expected convention for locally installed packages is to put them in the
690:file:`{...}/site-packages/` directory, but you may want to install Python
691modules into some arbitrary directory. For example, your site may have a
692convention of keeping all software related to the web server under :file:`/www`.
693Add-on Python modules might then belong in :file:`/www/python`, and in order to
694import them, this directory must be added to ``sys.path``. There are several
695different ways to add the directory.
696
697The most convenient way is to add a path configuration file to a directory
698that's already on Python's path, usually to the :file:`.../site-packages/`
699directory. Path configuration files have an extension of :file:`.pth`, and each
700line must contain a single path that will be appended to ``sys.path``. (Because
701the new paths are appended to ``sys.path``, modules in the added directories
702will not override standard modules. This means you can't use this mechanism for
703installing fixed versions of standard modules.)
704
705Paths can be absolute or relative, in which case they're relative to the
Brett Cannon5cf449c2007-11-17 07:07:29 +0000706directory containing the :file:`.pth` file. See the documentation of
Georg Brandlb3c572b2007-08-24 17:46:54 +0000707the :mod:`site` module for more information.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000708
709A slightly less convenient way is to edit the :file:`site.py` file in Python's
710standard library, and modify ``sys.path``. :file:`site.py` is automatically
711imported when the Python interpreter is executed, unless the :option:`-S` switch
712is supplied to suppress this behaviour. So you could simply edit
713:file:`site.py` and add two lines to it::
714
715 import sys
716 sys.path.append('/www/python/')
717
718However, if you reinstall the same major version of Python (perhaps when
719upgrading from 2.2 to 2.2.2, for example) :file:`site.py` will be overwritten by
720the stock version. You'd have to remember that it was modified and save a copy
721before doing the installation.
722
723There are two environment variables that can modify ``sys.path``.
724:envvar:`PYTHONHOME` sets an alternate value for the prefix of the Python
725installation. For example, if :envvar:`PYTHONHOME` is set to ``/www/python``,
726the search path will be set to ``['', '/www/python/lib/pythonX.Y/',
727'/www/python/lib/pythonX.Y/plat-linux2', ...]``.
728
729The :envvar:`PYTHONPATH` variable can be set to a list of paths that will be
730added to the beginning of ``sys.path``. For example, if :envvar:`PYTHONPATH` is
731set to ``/www/python:/opt/py``, the search path will begin with
732``['/www/python', '/opt/py']``. (Note that directories must exist in order to
733be added to ``sys.path``; the :mod:`site` module removes paths that don't
734exist.)
735
736Finally, ``sys.path`` is just a regular Python list, so any Python application
737can modify it by adding or removing entries.
738
739
740.. _inst-config-files:
741
742Distutils Configuration Files
743=============================
744
745As mentioned above, you can use Distutils configuration files to record personal
746or site preferences for any Distutils options. That is, any option to any
747command can be stored in one of two or three (depending on your platform)
748configuration files, which will be consulted before the command-line is parsed.
749This means that configuration files will override default values, and the
750command-line will in turn override configuration files. Furthermore, if
751multiple configuration files apply, values from "earlier" files are overridden
752by "later" files.
753
754
755.. _inst-config-filenames:
756
757Location and names of config files
758----------------------------------
759
760The names and locations of the configuration files vary slightly across
761platforms. On Unix and Mac OS X, the three configuration files (in the order
762they are processed) are:
763
764+--------------+----------------------------------------------------------+-------+
765| Type of file | Location and filename | Notes |
766+==============+==========================================================+=======+
767| system | :file:`{prefix}/lib/python{ver}/distutils/distutils.cfg` | \(1) |
768+--------------+----------------------------------------------------------+-------+
769| personal | :file:`$HOME/.pydistutils.cfg` | \(2) |
770+--------------+----------------------------------------------------------+-------+
771| local | :file:`setup.cfg` | \(3) |
772+--------------+----------------------------------------------------------+-------+
773
774And on Windows, the configuration files are:
775
776+--------------+-------------------------------------------------+-------+
777| Type of file | Location and filename | Notes |
778+==============+=================================================+=======+
779| system | :file:`{prefix}\\Lib\\distutils\\distutils.cfg` | \(4) |
780+--------------+-------------------------------------------------+-------+
781| personal | :file:`%HOME%\\pydistutils.cfg` | \(5) |
782+--------------+-------------------------------------------------+-------+
783| local | :file:`setup.cfg` | \(3) |
784+--------------+-------------------------------------------------+-------+
785
Tarek Ziadé40b998b2009-10-27 23:06:10 +0000786On all platforms, the "personal" file can be temporarily disabled by
787passing the `--no-user-cfg` option.
788
Georg Brandl8ec7f652007-08-15 14:28:01 +0000789Notes:
790
791(1)
792 Strictly speaking, the system-wide configuration file lives in the directory
793 where the Distutils are installed; under Python 1.6 and later on Unix, this is
794 as shown. For Python 1.5.2, the Distutils will normally be installed to
795 :file:`{prefix}/lib/python1.5/site-packages/distutils`, so the system
796 configuration file should be put there under Python 1.5.2.
797
798(2)
799 On Unix, if the :envvar:`HOME` environment variable is not defined, the user's
800 home directory will be determined with the :func:`getpwuid` function from the
Tarek Ziadéf7216662009-08-21 14:11:26 +0000801 standard :mod:`pwd` module. This is done by the :func:`os.path.expanduser`
802 function used by Distutils.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000803
804(3)
805 I.e., in the current directory (usually the location of the setup script).
806
807(4)
808 (See also note (1).) Under Python 1.6 and later, Python's default "installation
809 prefix" is :file:`C:\\Python`, so the system configuration file is normally
810 :file:`C:\\Python\\Lib\\distutils\\distutils.cfg`. Under Python 1.5.2, the
811 default prefix was :file:`C:\\Program Files\\Python`, and the Distutils were not
812 part of the standard library---so the system configuration file would be
813 :file:`C:\\Program Files\\Python\\distutils\\distutils.cfg` in a standard Python
814 1.5.2 installation under Windows.
815
816(5)
Tarek Ziadéf7216662009-08-21 14:11:26 +0000817 On Windows, if the :envvar:`HOME` environment variable is not defined,
818 :envvar:`USERPROFILE` then :envvar:`HOMEDRIVE` and :envvar:`HOMEPATH` will
819 be tried. This is done by the :func:`os.path.expanduser` function used
820 by Distutils.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000821
822
823.. _inst-config-syntax:
824
825Syntax of config files
826----------------------
827
828The Distutils configuration files all have the same syntax. The config files
829are grouped into sections. There is one section for each Distutils command,
830plus a ``global`` section for global options that affect every command. Each
831section consists of one option per line, specified as ``option=value``.
832
833For example, the following is a complete config file that just forces all
834commands to run quietly by default::
835
836 [global]
837 verbose=0
838
839If this is installed as the system config file, it will affect all processing of
840any Python module distribution by any user on the current system. If it is
841installed as your personal config file (on systems that support them), it will
842affect only module distributions processed by you. And if it is used as the
843:file:`setup.cfg` for a particular module distribution, it affects only that
844distribution.
845
846You could override the default "build base" directory and make the
847:command:`build\*` commands always forcibly rebuild all files with the
848following::
849
850 [build]
851 build-base=blib
852 force=1
853
854which corresponds to the command-line arguments ::
855
856 python setup.py build --build-base=blib --force
857
858except that including the :command:`build` command on the command-line means
859that command will be run. Including a particular command in config files has no
860such implication; it only means that if the command is run, the options in the
861config file will apply. (Or if other commands that derive values from it are
862run, they will use the values in the config file.)
863
864You can find out the complete list of options for any command using the
Martin Panterfb452162016-04-16 04:59:38 +0000865:option:`!--help` option, e.g.::
Georg Brandl8ec7f652007-08-15 14:28:01 +0000866
867 python setup.py build --help
868
869and you can find out the complete list of global options by using
Martin Panterfb452162016-04-16 04:59:38 +0000870:option:`!--help` without a command::
Georg Brandl8ec7f652007-08-15 14:28:01 +0000871
872 python setup.py --help
873
874See also the "Reference" section of the "Distributing Python Modules" manual.
875
876
877.. _inst-building-ext:
878
879Building Extensions: Tips and Tricks
880====================================
881
882Whenever possible, the Distutils try to use the configuration information made
883available by the Python interpreter used to run the :file:`setup.py` script.
884For example, the same compiler and linker flags used to compile Python will also
885be used for compiling extensions. Usually this will work well, but in
886complicated situations this might be inappropriate. This section discusses how
887to override the usual Distutils behaviour.
888
889
890.. _inst-tweak-flags:
891
892Tweaking compiler/linker flags
893------------------------------
894
895Compiling a Python extension written in C or C++ will sometimes require
896specifying custom flags for the compiler and linker in order to use a particular
897library or produce a special kind of object code. This is especially true if the
898extension hasn't been tested on your platform, or if you're trying to
899cross-compile Python.
900
901In the most general case, the extension author might have foreseen that
902compiling the extensions would be complicated, and provided a :file:`Setup` file
903for you to edit. This will likely only be done if the module distribution
904contains many separate extension modules, or if they often require elaborate
905sets of compiler flags in order to work.
906
907A :file:`Setup` file, if present, is parsed in order to get a list of extensions
908to build. Each line in a :file:`Setup` describes a single module. Lines have
909the following structure::
910
911 module ... [sourcefile ...] [cpparg ...] [library ...]
912
913
914Let's examine each of the fields in turn.
915
916* *module* is the name of the extension module to be built, and should be a
917 valid Python identifier. You can't just change this in order to rename a module
918 (edits to the source code would also be needed), so this should be left alone.
919
920* *sourcefile* is anything that's likely to be a source code file, at least
921 judging by the filename. Filenames ending in :file:`.c` are assumed to be
922 written in C, filenames ending in :file:`.C`, :file:`.cc`, and :file:`.c++` are
923 assumed to be C++, and filenames ending in :file:`.m` or :file:`.mm` are assumed
924 to be in Objective C.
925
926* *cpparg* is an argument for the C preprocessor, and is anything starting with
Martin Panterfb452162016-04-16 04:59:38 +0000927 :option:`!-I`, :option:`-D`, :option:`!-U` or :option:`-C`.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000928
929* *library* is anything ending in :file:`.a` or beginning with :option:`-l` or
930 :option:`-L`.
931
932If a particular platform requires a special library on your platform, you can
933add it by editing the :file:`Setup` file and running ``python setup.py build``.
934For example, if the module defined by the line ::
935
936 foo foomodule.c
937
938must be linked with the math library :file:`libm.a` on your platform, simply add
939:option:`-lm` to the line::
940
941 foo foomodule.c -lm
942
943Arbitrary switches intended for the compiler or the linker can be supplied with
944the :option:`-Xcompiler` *arg* and :option:`-Xlinker` *arg* options::
945
946 foo foomodule.c -Xcompiler -o32 -Xlinker -shared -lm
947
948The next option after :option:`-Xcompiler` and :option:`-Xlinker` will be
949appended to the proper command line, so in the above example the compiler will
950be passed the :option:`-o32` option, and the linker will be passed
951:option:`-shared`. If a compiler option requires an argument, you'll have to
952supply multiple :option:`-Xcompiler` options; for example, to pass ``-x c++``
953the :file:`Setup` file would have to contain ``-Xcompiler -x -Xcompiler c++``.
954
955Compiler flags can also be supplied through setting the :envvar:`CFLAGS`
956environment variable. If set, the contents of :envvar:`CFLAGS` will be added to
957the compiler flags specified in the :file:`Setup` file.
958
959
960.. _inst-non-ms-compilers:
961
962Using non-Microsoft compilers on Windows
963----------------------------------------
964
965.. sectionauthor:: Rene Liebscher <R.Liebscher@gmx.de>
966
967
968
Georg Brandl02677812008-03-15 00:20:19 +0000969Borland/CodeGear C++
970^^^^^^^^^^^^^^^^^^^^
Georg Brandl8ec7f652007-08-15 14:28:01 +0000971
Georg Brandl02677812008-03-15 00:20:19 +0000972This subsection describes the necessary steps to use Distutils with the Borland
Georg Brandl8ec7f652007-08-15 14:28:01 +0000973C++ compiler version 5.5. First you have to know that Borland's object file
974format (OMF) is different from the format used by the Python version you can
975download from the Python or ActiveState Web site. (Python is built with
976Microsoft Visual C++, which uses COFF as the object file format.) For this
977reason you have to convert Python's library :file:`python25.lib` into the
978Borland format. You can do this as follows:
979
Georg Brandlb19be572007-12-29 10:57:00 +0000980.. Should we mention that users have to create cfg-files for the compiler?
981.. see also http://community.borland.com/article/0,1410,21205,00.html
Georg Brandl8ec7f652007-08-15 14:28:01 +0000982
983::
984
985 coff2omf python25.lib python25_bcpp.lib
986
987The :file:`coff2omf` program comes with the Borland compiler. The file
988:file:`python25.lib` is in the :file:`Libs` directory of your Python
989installation. If your extension uses other libraries (zlib, ...) you have to
990convert them too.
991
992The converted files have to reside in the same directories as the normal
993libraries.
994
995How does Distutils manage to use these libraries with their changed names? If
996the extension needs a library (eg. :file:`foo`) Distutils checks first if it
997finds a library with suffix :file:`_bcpp` (eg. :file:`foo_bcpp.lib`) and then
998uses this library. In the case it doesn't find such a special library it uses
999the default name (:file:`foo.lib`.) [#]_
1000
1001To let Distutils compile your extension with Borland C++ you now have to type::
1002
1003 python setup.py build --compiler=bcpp
1004
1005If you want to use the Borland C++ compiler as the default, you could specify
1006this in your personal or system-wide configuration file for Distutils (see
1007section :ref:`inst-config-files`.)
1008
1009
1010.. seealso::
1011
Serhiy Storchakab4905ef2016-05-07 10:50:12 +03001012 `C++Builder Compiler <https://www.embarcadero.com/products>`_
Georg Brandl8ec7f652007-08-15 14:28:01 +00001013 Information about the free C++ compiler from Borland, including links to the
1014 download pages.
1015
1016 `Creating Python Extensions Using Borland's Free Compiler <http://www.cyberus.ca/~g_will/pyExtenDL.shtml>`_
1017 Document describing how to use Borland's free command-line C++ compiler to build
1018 Python.
1019
1020
1021GNU C / Cygwin / MinGW
1022^^^^^^^^^^^^^^^^^^^^^^
1023
Georg Brandl8ec7f652007-08-15 14:28:01 +00001024This section describes the necessary steps to use Distutils with the GNU C/C++
1025compilers in their Cygwin and MinGW distributions. [#]_ For a Python interpreter
1026that was built with Cygwin, everything should work without any of these
1027following steps.
1028
Éric Araujobe98fab2010-12-15 22:20:15 +00001029Not all extensions can be built with MinGW or Cygwin, but many can. Extensions
1030most likely to not work are those that use C++ or depend on Microsoft Visual C
1031extensions.
1032
1033To let Distutils compile your extension with Cygwin you have to type::
1034
1035 python setup.py build --compiler=cygwin
1036
1037and for Cygwin in no-cygwin mode [#]_ or for MinGW type::
1038
1039 python setup.py build --compiler=mingw32
1040
1041If you want to use any of these options/compilers as default, you should
1042consider writing it in your personal or system-wide configuration file for
1043Distutils (see section :ref:`inst-config-files`.)
1044
1045Older Versions of Python and MinGW
1046""""""""""""""""""""""""""""""""""
1047The following instructions only apply if you're using a version of Python
1048inferior to 2.4.1 with a MinGW inferior to 3.0.0 (with
1049binutils-2.13.90-20030111-1).
1050
1051These compilers require some special libraries. This task is more complex than
Georg Brandl8ec7f652007-08-15 14:28:01 +00001052for Borland's C++, because there is no program to convert the library. First
1053you have to create a list of symbols which the Python DLL exports. (You can find
Georg Brandla4314c22009-10-11 20:16:16 +00001054a good program for this task at
Serhiy Storchakab4905ef2016-05-07 10:50:12 +03001055https://sourceforge.net/projects/mingw/files/MinGW/Extension/pexports/).
Georg Brandl8ec7f652007-08-15 14:28:01 +00001056
Georg Brandlb19be572007-12-29 10:57:00 +00001057.. I don't understand what the next line means. --amk
1058.. (inclusive the references on data structures.)
Georg Brandl8ec7f652007-08-15 14:28:01 +00001059
1060::
1061
1062 pexports python25.dll >python25.def
1063
1064The location of an installed :file:`python25.dll` will depend on the
1065installation options and the version and language of Windows. In a "just for
1066me" installation, it will appear in the root of the installation directory. In
1067a shared installation, it will be located in the system directory.
1068
1069Then you can create from these information an import library for gcc. ::
1070
1071 /cygwin/bin/dlltool --dllname python25.dll --def python25.def --output-lib libpython25.a
1072
1073The resulting library has to be placed in the same directory as
1074:file:`python25.lib`. (Should be the :file:`libs` directory under your Python
1075installation directory.)
1076
1077If your extension uses other libraries (zlib,...) you might have to convert
1078them too. The converted files have to reside in the same directories as the
1079normal libraries do.
1080
Georg Brandl8ec7f652007-08-15 14:28:01 +00001081
1082.. seealso::
1083
Georg Brandl97ae4662014-10-29 10:26:56 +01001084 `Building Python modules on MS Windows platform with MinGW <http://old.zope.org/Members/als/tips/win32_mingw_modules>`_
Georg Brandl8ec7f652007-08-15 14:28:01 +00001085 Information about building the required libraries for the MinGW environment.
1086
Georg Brandl8ec7f652007-08-15 14:28:01 +00001087
1088.. rubric:: Footnotes
1089
1090.. [#] This also means you could replace all existing COFF-libraries with OMF-libraries
1091 of the same name.
1092
Serhiy Storchakab4905ef2016-05-07 10:50:12 +03001093.. [#] Check https://www.sourceware.org/cygwin/ and http://www.mingw.org/ for more
Georg Brandl8ec7f652007-08-15 14:28:01 +00001094 information
1095
1096.. [#] Then you have no POSIX emulation available, but you also don't need
1097 :file:`cygwin1.dll`.