Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1 | .. _built-dist: |
| 2 | |
| 3 | **************************** |
| 4 | Creating Built Distributions |
| 5 | **************************** |
| 6 | |
| 7 | A "built distribution" is what you're probably used to thinking of either as a |
| 8 | "binary package" or an "installer" (depending on your background). It's not |
| 9 | necessarily binary, though, because it might contain only Python source code |
| 10 | and/or byte-code; and we don't call it a package, because that word is already |
| 11 | spoken for in Python. (And "installer" is a term specific to the world of |
| 12 | mainstream desktop systems.) |
| 13 | |
| 14 | A built distribution is how you make life as easy as possible for installers of |
| 15 | your module distribution: for users of RPM-based Linux systems, it's a binary |
| 16 | RPM; for Windows users, it's an executable installer; for Debian-based Linux |
| 17 | users, it's a Debian package; and so forth. Obviously, no one person will be |
| 18 | able to create built distributions for every platform under the sun, so the |
| 19 | Distutils are designed to enable module developers to concentrate on their |
| 20 | specialty---writing code and creating source distributions---while an |
| 21 | intermediary species called *packagers* springs up to turn source distributions |
| 22 | into built distributions for as many platforms as there are packagers. |
| 23 | |
Andrés Delfino | 5092439 | 2018-06-18 01:34:30 -0300 | [diff] [blame] | 24 | Of course, the module developer could be their own packager; or the packager could |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 25 | be a volunteer "out there" somewhere who has access to a platform which the |
| 26 | original developer does not; or it could be software periodically grabbing new |
| 27 | source distributions and turning them into built distributions for as many |
| 28 | platforms as the software has access to. Regardless of who they are, a packager |
| 29 | uses the setup script and the :command:`bdist` command family to generate built |
| 30 | distributions. |
| 31 | |
| 32 | As a simple example, if I run the following command in the Distutils source |
| 33 | tree:: |
| 34 | |
| 35 | python setup.py bdist |
| 36 | |
| 37 | then the Distutils builds my module distribution (the Distutils itself in this |
| 38 | case), does a "fake" installation (also in the :file:`build` directory), and |
| 39 | creates the default type of built distribution for my platform. The default |
| 40 | format for built distributions is a "dumb" tar file on Unix, and a simple |
| 41 | executable installer on Windows. (That tar file is considered "dumb" because it |
| 42 | has to be unpacked in a specific location to work.) |
| 43 | |
| 44 | Thus, the above command on a Unix system creates |
| 45 | :file:`Distutils-1.0.{plat}.tar.gz`; unpacking this tarball from the right place |
| 46 | installs the Distutils just as though you had downloaded the source distribution |
| 47 | and run ``python setup.py install``. (The "right place" is either the root of |
| 48 | the filesystem or Python's :file:`{prefix}` directory, depending on the options |
| 49 | given to the :command:`bdist_dumb` command; the default is to make dumb |
| 50 | distributions relative to :file:`{prefix}`.) |
| 51 | |
| 52 | Obviously, for pure Python distributions, this isn't any simpler than just |
| 53 | running ``python setup.py install``\ ---but for non-pure distributions, which |
| 54 | include extensions that would need to be compiled, it can mean the difference |
| 55 | between someone being able to use your extensions or not. And creating "smart" |
| 56 | built distributions, such as an RPM package or an executable installer for |
| 57 | Windows, is far more convenient for users even if your distribution doesn't |
| 58 | include any extensions. |
| 59 | |
Martin Panter | 5c67933 | 2016-10-30 04:20:17 +0000 | [diff] [blame] | 60 | The :command:`bdist` command has a :option:`!--formats` option, similar to the |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 61 | :command:`sdist` command, which you can use to select the types of built |
| 62 | distribution to generate: for example, :: |
| 63 | |
| 64 | python setup.py bdist --format=zip |
| 65 | |
Serhiy Storchaka | 3f819ca | 2018-10-31 02:26:06 +0200 | [diff] [blame] | 66 | would, when run on a Unix system, create |
| 67 | :file:`Distutils-1.0.{plat}.zip`\ ---again, this archive would be unpacked |
| 68 | from the root directory to install the Distutils. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 69 | |
| 70 | The available formats for built distributions are: |
| 71 | |
| 72 | +-------------+------------------------------+---------+ |
| 73 | | Format | Description | Notes | |
| 74 | +=============+==============================+=========+ |
Serhiy Storchaka | b9cec6a | 2015-05-16 22:13:27 +0300 | [diff] [blame] | 75 | | ``gztar`` | gzipped tar file | \(1) | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 76 | | | (:file:`.tar.gz`) | | |
| 77 | +-------------+------------------------------+---------+ |
Serhiy Storchaka | b9cec6a | 2015-05-16 22:13:27 +0300 | [diff] [blame] | 78 | | ``bztar`` | bzipped tar file | | |
| 79 | | | (:file:`.tar.bz2`) | | |
| 80 | +-------------+------------------------------+---------+ |
| 81 | | ``xztar`` | xzipped tar file | | |
| 82 | | | (:file:`.tar.xz`) | | |
| 83 | +-------------+------------------------------+---------+ |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 84 | | ``ztar`` | compressed tar file | \(3) | |
| 85 | | | (:file:`.tar.Z`) | | |
| 86 | +-------------+------------------------------+---------+ |
Serhiy Storchaka | b9cec6a | 2015-05-16 22:13:27 +0300 | [diff] [blame] | 87 | | ``tar`` | tar file (:file:`.tar`) | | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 88 | +-------------+------------------------------+---------+ |
Tarek Ziadé | f637050 | 2009-04-05 22:57:21 +0000 | [diff] [blame] | 89 | | ``zip`` | zip file (:file:`.zip`) | (2),(4) | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 90 | +-------------+------------------------------+---------+ |
| 91 | | ``rpm`` | RPM | \(5) | |
| 92 | +-------------+------------------------------+---------+ |
| 93 | | ``pkgtool`` | Solaris :program:`pkgtool` | | |
| 94 | +-------------+------------------------------+---------+ |
| 95 | | ``sdux`` | HP-UX :program:`swinstall` | | |
| 96 | +-------------+------------------------------+---------+ |
Tarek Ziadé | f637050 | 2009-04-05 22:57:21 +0000 | [diff] [blame] | 97 | | ``wininst`` | self-extracting ZIP file for | \(4) | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 98 | | | Windows | | |
| 99 | +-------------+------------------------------+---------+ |
Tarek Ziadé | f637050 | 2009-04-05 22:57:21 +0000 | [diff] [blame] | 100 | | ``msi`` | Microsoft Installer. | | |
| 101 | +-------------+------------------------------+---------+ |
| 102 | |
Zachary Ware | 7f142c7 | 2015-07-07 00:11:36 -0500 | [diff] [blame] | 103 | .. versionchanged:: 3.5 |
Serhiy Storchaka | b9cec6a | 2015-05-16 22:13:27 +0300 | [diff] [blame] | 104 | Added support for the ``xztar`` format. |
| 105 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 106 | |
| 107 | Notes: |
| 108 | |
| 109 | (1) |
| 110 | default on Unix |
| 111 | |
| 112 | (2) |
| 113 | default on Windows |
| 114 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 115 | (3) |
Serhiy Storchaka | b9cec6a | 2015-05-16 22:13:27 +0300 | [diff] [blame] | 116 | requires external :program:`compress` utility. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 117 | |
| 118 | (4) |
| 119 | requires either external :program:`zip` utility or :mod:`zipfile` module (part |
| 120 | of the standard Python library since Python 1.6) |
| 121 | |
| 122 | (5) |
| 123 | requires external :program:`rpm` utility, version 3.0.4 or better (use ``rpm |
| 124 | --version`` to find out which version you have) |
| 125 | |
Martin Panter | 5c67933 | 2016-10-30 04:20:17 +0000 | [diff] [blame] | 126 | You don't have to use the :command:`bdist` command with the :option:`!--formats` |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 127 | option; you can also use the command that directly implements the format you're |
| 128 | interested in. Some of these :command:`bdist` "sub-commands" actually generate |
| 129 | several similar formats; for instance, the :command:`bdist_dumb` command |
Serhiy Storchaka | b9cec6a | 2015-05-16 22:13:27 +0300 | [diff] [blame] | 130 | generates all the "dumb" archive formats (``tar``, ``gztar``, ``bztar``, |
| 131 | ``xztar``, ``ztar``, and ``zip``), and :command:`bdist_rpm` generates both |
| 132 | binary and source RPMs. The :command:`bdist` sub-commands, and the formats |
| 133 | generated by each, are: |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 134 | |
Serhiy Storchaka | b9cec6a | 2015-05-16 22:13:27 +0300 | [diff] [blame] | 135 | +--------------------------+-------------------------------------+ |
| 136 | | Command | Formats | |
| 137 | +==========================+=====================================+ |
| 138 | | :command:`bdist_dumb` | tar, gztar, bztar, xztar, ztar, zip | |
| 139 | +--------------------------+-------------------------------------+ |
| 140 | | :command:`bdist_rpm` | rpm, srpm | |
| 141 | +--------------------------+-------------------------------------+ |
| 142 | | :command:`bdist_wininst` | wininst | |
| 143 | +--------------------------+-------------------------------------+ |
| 144 | | :command:`bdist_msi` | msi | |
| 145 | +--------------------------+-------------------------------------+ |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 146 | |
| 147 | The following sections give details on the individual :command:`bdist_\*` |
| 148 | commands. |
| 149 | |
| 150 | |
Georg Brandl | d5f2d6e | 2010-07-31 09:15:10 +0000 | [diff] [blame] | 151 | .. .. _creating-dumb: |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 152 | |
Georg Brandl | d5f2d6e | 2010-07-31 09:15:10 +0000 | [diff] [blame] | 153 | .. Creating dumb built distributions |
| 154 | .. ================================= |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 155 | |
Georg Brandl | d5f2d6e | 2010-07-31 09:15:10 +0000 | [diff] [blame] | 156 | .. XXX Need to document absolute vs. prefix-relative packages here, but first |
| 157 | I have to implement it! |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 158 | |
| 159 | |
| 160 | .. _creating-rpms: |
| 161 | |
| 162 | Creating RPM packages |
| 163 | ===================== |
| 164 | |
| 165 | The RPM format is used by many popular Linux distributions, including Red Hat, |
| 166 | SuSE, and Mandrake. If one of these (or any of the other RPM-based Linux |
| 167 | distributions) is your usual environment, creating RPM packages for other users |
| 168 | of that same distribution is trivial. Depending on the complexity of your module |
| 169 | distribution and differences between Linux distributions, you may also be able |
| 170 | to create RPMs that work on different RPM-based distributions. |
| 171 | |
| 172 | The usual way to create an RPM of your module distribution is to run the |
| 173 | :command:`bdist_rpm` command:: |
| 174 | |
| 175 | python setup.py bdist_rpm |
| 176 | |
Martin Panter | 5c67933 | 2016-10-30 04:20:17 +0000 | [diff] [blame] | 177 | or the :command:`bdist` command with the :option:`!--format` option:: |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 178 | |
| 179 | python setup.py bdist --formats=rpm |
| 180 | |
| 181 | The former allows you to specify RPM-specific options; the latter allows you to |
| 182 | easily specify multiple formats in one run. If you need to do both, you can |
| 183 | explicitly specify multiple :command:`bdist_\*` commands and their options:: |
| 184 | |
| 185 | python setup.py bdist_rpm --packager="John Doe <jdoe@example.org>" \ |
Georg Brandl | 56be37c | 2010-08-02 19:16:34 +0000 | [diff] [blame] | 186 | bdist_wininst --target-version="2.0" |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 187 | |
| 188 | Creating RPM packages is driven by a :file:`.spec` file, much as using the |
| 189 | Distutils is driven by the setup script. To make your life easier, the |
| 190 | :command:`bdist_rpm` command normally creates a :file:`.spec` file based on the |
| 191 | information you supply in the setup script, on the command line, and in any |
| 192 | Distutils configuration files. Various options and sections in the |
| 193 | :file:`.spec` file are derived from options in the setup script as follows: |
| 194 | |
| 195 | +------------------------------------------+----------------------------------------------+ |
| 196 | | RPM :file:`.spec` file option or section | Distutils setup script option | |
| 197 | +==========================================+==============================================+ |
Georg Brandl | 3f40c40 | 2014-09-21 00:35:08 +0200 | [diff] [blame] | 198 | | Name | ``name`` | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 199 | +------------------------------------------+----------------------------------------------+ |
Georg Brandl | 3f40c40 | 2014-09-21 00:35:08 +0200 | [diff] [blame] | 200 | | Summary (in preamble) | ``description`` | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 201 | +------------------------------------------+----------------------------------------------+ |
Georg Brandl | 3f40c40 | 2014-09-21 00:35:08 +0200 | [diff] [blame] | 202 | | Version | ``version`` | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 203 | +------------------------------------------+----------------------------------------------+ |
Georg Brandl | 3f40c40 | 2014-09-21 00:35:08 +0200 | [diff] [blame] | 204 | | Vendor | ``author`` and ``author_email``, | |
| 205 | | | or --- & ``maintainer`` and | |
| 206 | | | ``maintainer_email`` | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 207 | +------------------------------------------+----------------------------------------------+ |
Georg Brandl | 3f40c40 | 2014-09-21 00:35:08 +0200 | [diff] [blame] | 208 | | Copyright | ``license`` | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 209 | +------------------------------------------+----------------------------------------------+ |
Georg Brandl | 3f40c40 | 2014-09-21 00:35:08 +0200 | [diff] [blame] | 210 | | Url | ``url`` | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 211 | +------------------------------------------+----------------------------------------------+ |
Georg Brandl | 3f40c40 | 2014-09-21 00:35:08 +0200 | [diff] [blame] | 212 | | %description (section) | ``long_description`` | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 213 | +------------------------------------------+----------------------------------------------+ |
| 214 | |
| 215 | Additionally, there are many options in :file:`.spec` files that don't have |
| 216 | corresponding options in the setup script. Most of these are handled through |
| 217 | options to the :command:`bdist_rpm` command as follows: |
| 218 | |
| 219 | +-------------------------------+-----------------------------+-------------------------+ |
| 220 | | RPM :file:`.spec` file option | :command:`bdist_rpm` option | default value | |
| 221 | | or section | | | |
| 222 | +===============================+=============================+=========================+ |
Georg Brandl | 3f40c40 | 2014-09-21 00:35:08 +0200 | [diff] [blame] | 223 | | Release | ``release`` | "1" | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 224 | +-------------------------------+-----------------------------+-------------------------+ |
Georg Brandl | 3f40c40 | 2014-09-21 00:35:08 +0200 | [diff] [blame] | 225 | | Group | ``group`` | "Development/Libraries" | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 226 | +-------------------------------+-----------------------------+-------------------------+ |
Georg Brandl | 3f40c40 | 2014-09-21 00:35:08 +0200 | [diff] [blame] | 227 | | Vendor | ``vendor`` | (see above) | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 228 | +-------------------------------+-----------------------------+-------------------------+ |
Georg Brandl | 3f40c40 | 2014-09-21 00:35:08 +0200 | [diff] [blame] | 229 | | Packager | ``packager`` | (none) | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 230 | +-------------------------------+-----------------------------+-------------------------+ |
Georg Brandl | 3f40c40 | 2014-09-21 00:35:08 +0200 | [diff] [blame] | 231 | | Provides | ``provides`` | (none) | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 232 | +-------------------------------+-----------------------------+-------------------------+ |
Georg Brandl | 3f40c40 | 2014-09-21 00:35:08 +0200 | [diff] [blame] | 233 | | Requires | ``requires`` | (none) | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 234 | +-------------------------------+-----------------------------+-------------------------+ |
Georg Brandl | 3f40c40 | 2014-09-21 00:35:08 +0200 | [diff] [blame] | 235 | | Conflicts | ``conflicts`` | (none) | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 236 | +-------------------------------+-----------------------------+-------------------------+ |
Georg Brandl | 3f40c40 | 2014-09-21 00:35:08 +0200 | [diff] [blame] | 237 | | Obsoletes | ``obsoletes`` | (none) | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 238 | +-------------------------------+-----------------------------+-------------------------+ |
Georg Brandl | 3f40c40 | 2014-09-21 00:35:08 +0200 | [diff] [blame] | 239 | | Distribution | ``distribution_name`` | (none) | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 240 | +-------------------------------+-----------------------------+-------------------------+ |
Georg Brandl | 3f40c40 | 2014-09-21 00:35:08 +0200 | [diff] [blame] | 241 | | BuildRequires | ``build_requires`` | (none) | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 242 | +-------------------------------+-----------------------------+-------------------------+ |
Georg Brandl | 3f40c40 | 2014-09-21 00:35:08 +0200 | [diff] [blame] | 243 | | Icon | ``icon`` | (none) | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 244 | +-------------------------------+-----------------------------+-------------------------+ |
| 245 | |
| 246 | Obviously, supplying even a few of these options on the command-line would be |
| 247 | tedious and error-prone, so it's usually best to put them in the setup |
| 248 | configuration file, :file:`setup.cfg`\ ---see section :ref:`setup-config`. If |
| 249 | you distribute or package many Python module distributions, you might want to |
| 250 | put options that apply to all of them in your personal Distutils configuration |
Andrew Kuchling | 2a1838b | 2013-11-10 18:11:00 -0500 | [diff] [blame] | 251 | file (:file:`~/.pydistutils.cfg`). If you want to temporarily disable |
Martin Panter | 5c67933 | 2016-10-30 04:20:17 +0000 | [diff] [blame] | 252 | this file, you can pass the :option:`!--no-user-cfg` option to :file:`setup.py`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 253 | |
| 254 | There are three steps to building a binary RPM package, all of which are |
| 255 | handled automatically by the Distutils: |
| 256 | |
| 257 | #. create a :file:`.spec` file, which describes the package (analogous to the |
| 258 | Distutils setup script; in fact, much of the information in the setup script |
| 259 | winds up in the :file:`.spec` file) |
| 260 | |
| 261 | #. create the source RPM |
| 262 | |
| 263 | #. create the "binary" RPM (which may or may not contain binary code, depending |
| 264 | on whether your module distribution contains Python extensions) |
| 265 | |
| 266 | Normally, RPM bundles the last two steps together; when you use the Distutils, |
| 267 | all three steps are typically bundled together. |
| 268 | |
| 269 | If you wish, you can separate these three steps. You can use the |
Martin Panter | 5c67933 | 2016-10-30 04:20:17 +0000 | [diff] [blame] | 270 | :option:`!--spec-only` option to make :command:`bdist_rpm` just create the |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 271 | :file:`.spec` file and exit; in this case, the :file:`.spec` file will be |
| 272 | written to the "distribution directory"---normally :file:`dist/`, but |
Martin Panter | 5c67933 | 2016-10-30 04:20:17 +0000 | [diff] [blame] | 273 | customizable with the :option:`!--dist-dir` option. (Normally, the :file:`.spec` |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 274 | file winds up deep in the "build tree," in a temporary directory created by |
| 275 | :command:`bdist_rpm`.) |
| 276 | |
| 277 | .. % \XXX{this isn't implemented yet---is it needed?!} |
| 278 | .. % You can also specify a custom \file{.spec} file with the |
| 279 | .. % \longprogramopt{spec-file} option; used in conjunction with |
| 280 | .. % \longprogramopt{spec-only}, this gives you an opportunity to customize |
| 281 | .. % the \file{.spec} file manually: |
Georg Brandl | 48310cd | 2009-01-03 21:18:54 +0000 | [diff] [blame] | 282 | .. % |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 283 | .. % \ begin{verbatim} |
| 284 | .. % > python setup.py bdist_rpm --spec-only |
| 285 | .. % # ...edit dist/FooBar-1.0.spec |
| 286 | .. % > python setup.py bdist_rpm --spec-file=dist/FooBar-1.0.spec |
| 287 | .. % \ end{verbatim} |
Georg Brandl | 48310cd | 2009-01-03 21:18:54 +0000 | [diff] [blame] | 288 | .. % |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 289 | .. % (Although a better way to do this is probably to override the standard |
| 290 | .. % \command{bdist\_rpm} command with one that writes whatever else you want |
| 291 | .. % to the \file{.spec} file.) |
| 292 | |
| 293 | |
| 294 | .. _creating-wininst: |
| 295 | |
| 296 | Creating Windows Installers |
| 297 | =========================== |
| 298 | |
| 299 | Executable installers are the natural format for binary distributions on |
| 300 | Windows. They display a nice graphical user interface, display some information |
| 301 | about the module distribution to be installed taken from the metadata in the |
| 302 | setup script, let the user select a few options, and start or cancel the |
| 303 | installation. |
| 304 | |
| 305 | Since the metadata is taken from the setup script, creating Windows installers |
| 306 | is usually as easy as running:: |
| 307 | |
| 308 | python setup.py bdist_wininst |
| 309 | |
Martin Panter | 5c67933 | 2016-10-30 04:20:17 +0000 | [diff] [blame] | 310 | or the :command:`bdist` command with the :option:`!--formats` option:: |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 311 | |
| 312 | python setup.py bdist --formats=wininst |
| 313 | |
| 314 | If you have a pure module distribution (only containing pure Python modules and |
| 315 | packages), the resulting installer will be version independent and have a name |
Georg Brandl | c575c90 | 2008-09-13 17:46:05 +0000 | [diff] [blame] | 316 | like :file:`foo-1.0.win32.exe`. These installers can even be created on Unix |
| 317 | platforms or Mac OS X. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 318 | |
| 319 | If you have a non-pure distribution, the extensions can only be created on a |
| 320 | Windows platform, and will be Python version dependent. The installer filename |
| 321 | will reflect this and now has the form :file:`foo-1.0.win32-py2.0.exe`. You |
| 322 | have to create a separate installer for every Python version you want to |
| 323 | support. |
| 324 | |
Georg Brandl | 9afde1c | 2007-11-01 20:32:30 +0000 | [diff] [blame] | 325 | The installer will try to compile pure modules into :term:`bytecode` after installation |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 326 | on the target system in normal and optimizing mode. If you don't want this to |
| 327 | happen for some reason, you can run the :command:`bdist_wininst` command with |
Martin Panter | 5c67933 | 2016-10-30 04:20:17 +0000 | [diff] [blame] | 328 | the :option:`!--no-target-compile` and/or the :option:`!--no-target-optimize` |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 329 | option. |
| 330 | |
| 331 | By default the installer will display the cool "Python Powered" logo when it is |
Benjamin Peterson | d7c3ed5 | 2010-06-27 22:32:30 +0000 | [diff] [blame] | 332 | run, but you can also supply your own 152x261 bitmap which must be a Windows |
Martin Panter | 5c67933 | 2016-10-30 04:20:17 +0000 | [diff] [blame] | 333 | :file:`.bmp` file with the :option:`!--bitmap` option. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 334 | |
| 335 | The installer will also display a large title on the desktop background window |
| 336 | when it is run, which is constructed from the name of your distribution and the |
| 337 | version number. This can be changed to another text by using the |
Martin Panter | 5c67933 | 2016-10-30 04:20:17 +0000 | [diff] [blame] | 338 | :option:`!--title` option. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 339 | |
| 340 | The installer file will be written to the "distribution directory" --- normally |
Martin Panter | 5c67933 | 2016-10-30 04:20:17 +0000 | [diff] [blame] | 341 | :file:`dist/`, but customizable with the :option:`!--dist-dir` option. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 342 | |
Christian Heimes | 5e69685 | 2008-04-09 08:37:03 +0000 | [diff] [blame] | 343 | .. _cross-compile-windows: |
| 344 | |
| 345 | Cross-compiling on Windows |
| 346 | ========================== |
| 347 | |
Georg Brandl | 48310cd | 2009-01-03 21:18:54 +0000 | [diff] [blame] | 348 | Starting with Python 2.6, distutils is capable of cross-compiling between |
| 349 | Windows platforms. In practice, this means that with the correct tools |
Christian Heimes | 5e69685 | 2008-04-09 08:37:03 +0000 | [diff] [blame] | 350 | installed, you can use a 32bit version of Windows to create 64bit extensions |
| 351 | and vice-versa. |
| 352 | |
Martin Panter | 5c67933 | 2016-10-30 04:20:17 +0000 | [diff] [blame] | 353 | To build for an alternate platform, specify the :option:`!--plat-name` option |
Zachary Ware | 49ce74e | 2017-09-06 15:45:25 -0700 | [diff] [blame] | 354 | to the build command. Valid values are currently 'win32', and 'win-amd64'. |
| 355 | For example, on a 32bit version of Windows, you could execute:: |
Christian Heimes | 5e69685 | 2008-04-09 08:37:03 +0000 | [diff] [blame] | 356 | |
| 357 | python setup.py build --plat-name=win-amd64 |
| 358 | |
Georg Brandl | 48310cd | 2009-01-03 21:18:54 +0000 | [diff] [blame] | 359 | to build a 64bit version of your extension. The Windows Installers also |
Christian Heimes | 5e69685 | 2008-04-09 08:37:03 +0000 | [diff] [blame] | 360 | support this option, so the command:: |
| 361 | |
| 362 | python setup.py build --plat-name=win-amd64 bdist_wininst |
| 363 | |
| 364 | would create a 64bit installation executable on your 32bit version of Windows. |
| 365 | |
Georg Brandl | 48310cd | 2009-01-03 21:18:54 +0000 | [diff] [blame] | 366 | To cross-compile, you must download the Python source code and cross-compile |
Donald Stufft | 8b852f1 | 2014-05-20 12:58:38 -0400 | [diff] [blame] | 367 | Python itself for the platform you are targeting - it is not possible from a |
Georg Brandl | 6faee4e | 2010-09-21 14:48:28 +0000 | [diff] [blame] | 368 | binary installation of Python (as the .lib etc file for other platforms are |
Georg Brandl | 48310cd | 2009-01-03 21:18:54 +0000 | [diff] [blame] | 369 | not included.) In practice, this means the user of a 32 bit operating |
| 370 | system will need to use Visual Studio 2008 to open the |
Stefan Grönke | f1502d0 | 2017-09-25 18:58:10 +0200 | [diff] [blame] | 371 | :file:`PCbuild/PCbuild.sln` solution in the Python source tree and build the |
Georg Brandl | 48310cd | 2009-01-03 21:18:54 +0000 | [diff] [blame] | 372 | "x64" configuration of the 'pythoncore' project before cross-compiling |
Christian Heimes | 5e69685 | 2008-04-09 08:37:03 +0000 | [diff] [blame] | 373 | extensions is possible. |
| 374 | |
| 375 | Note that by default, Visual Studio 2008 does not install 64bit compilers or |
| 376 | tools. You may need to reexecute the Visual Studio setup process and select |
| 377 | these tools (using Control Panel->[Add/Remove] Programs is a convenient way to |
| 378 | check or modify your existing install.) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 379 | |
| 380 | .. _postinstallation-script: |
| 381 | |
| 382 | The Postinstallation script |
| 383 | --------------------------- |
| 384 | |
Benjamin Peterson | d7c3ed5 | 2010-06-27 22:32:30 +0000 | [diff] [blame] | 385 | Starting with Python 2.3, a postinstallation script can be specified with the |
Martin Panter | 5c67933 | 2016-10-30 04:20:17 +0000 | [diff] [blame] | 386 | :option:`!--install-script` option. The basename of the script must be |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 387 | specified, and the script filename must also be listed in the scripts argument |
| 388 | to the setup function. |
| 389 | |
| 390 | This script will be run at installation time on the target system after all the |
Martin Panter | 5c67933 | 2016-10-30 04:20:17 +0000 | [diff] [blame] | 391 | files have been copied, with ``argv[1]`` set to :option:`!-install`, and again at |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 392 | uninstallation time before the files are removed with ``argv[1]`` set to |
Martin Panter | 5c67933 | 2016-10-30 04:20:17 +0000 | [diff] [blame] | 393 | :option:`!-remove`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 394 | |
| 395 | The installation script runs embedded in the windows installer, every output |
| 396 | (``sys.stdout``, ``sys.stderr``) is redirected into a buffer and will be |
| 397 | displayed in the GUI after the script has finished. |
| 398 | |
| 399 | Some functions especially useful in this context are available as additional |
| 400 | built-in functions in the installation script. |
| 401 | |
| 402 | |
| 403 | .. function:: directory_created(path) |
| 404 | file_created(path) |
| 405 | |
| 406 | These functions should be called when a directory or file is created by the |
| 407 | postinstall script at installation time. It will register *path* with the |
| 408 | uninstaller, so that it will be removed when the distribution is uninstalled. |
| 409 | To be safe, directories are only removed if they are empty. |
| 410 | |
| 411 | |
| 412 | .. function:: get_special_folder_path(csidl_string) |
| 413 | |
| 414 | This function can be used to retrieve special folder locations on Windows like |
| 415 | the Start Menu or the Desktop. It returns the full path to the folder. |
| 416 | *csidl_string* must be one of the following strings:: |
| 417 | |
| 418 | "CSIDL_APPDATA" |
| 419 | |
| 420 | "CSIDL_COMMON_STARTMENU" |
| 421 | "CSIDL_STARTMENU" |
| 422 | |
| 423 | "CSIDL_COMMON_DESKTOPDIRECTORY" |
| 424 | "CSIDL_DESKTOPDIRECTORY" |
| 425 | |
| 426 | "CSIDL_COMMON_STARTUP" |
| 427 | "CSIDL_STARTUP" |
| 428 | |
| 429 | "CSIDL_COMMON_PROGRAMS" |
| 430 | "CSIDL_PROGRAMS" |
| 431 | |
| 432 | "CSIDL_FONTS" |
| 433 | |
| 434 | If the folder cannot be retrieved, :exc:`OSError` is raised. |
| 435 | |
| 436 | Which folders are available depends on the exact Windows version, and probably |
| 437 | also the configuration. For details refer to Microsoft's documentation of the |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 438 | :c:func:`SHGetSpecialFolderPath` function. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 439 | |
| 440 | |
| 441 | .. function:: create_shortcut(target, description, filename[, arguments[, workdir[, iconpath[, iconindex]]]]) |
| 442 | |
| 443 | This function creates a shortcut. *target* is the path to the program to be |
| 444 | started by the shortcut. *description* is the description of the shortcut. |
| 445 | *filename* is the title of the shortcut that the user will see. *arguments* |
| 446 | specifies the command line arguments, if any. *workdir* is the working directory |
| 447 | for the program. *iconpath* is the file containing the icon for the shortcut, |
| 448 | and *iconindex* is the index of the icon in the file *iconpath*. Again, for |
| 449 | details consult the Microsoft documentation for the :class:`IShellLink` |
| 450 | interface. |
Benjamin Peterson | 8719ad5 | 2009-09-11 22:24:02 +0000 | [diff] [blame] | 451 | |
| 452 | |
| 453 | Vista User Access Control (UAC) |
| 454 | =============================== |
| 455 | |
Martin Panter | 5c67933 | 2016-10-30 04:20:17 +0000 | [diff] [blame] | 456 | Starting with Python 2.6, bdist_wininst supports a :option:`!--user-access-control` |
Benjamin Peterson | 8719ad5 | 2009-09-11 22:24:02 +0000 | [diff] [blame] | 457 | option. The default is 'none' (meaning no UAC handling is done), and other |
| 458 | valid values are 'auto' (meaning prompt for UAC elevation if Python was |
| 459 | installed for all users) and 'force' (meaning always prompt for elevation). |