blob: f01b084a1997b490fe9a29dc49f18153a90ad6f5 [file] [log] [blame]
Donald Stufft527d4ac2014-11-20 09:38:31 -05001.. highlightlang:: none
2
3.. _installing-index:
4
5*****************************
6 Installing Python Modules
7*****************************
8
9:Email: distutils-sig@python.org
10
11As a popular open source development project, Python has an active
12supporting community of contributors and users that also make their software
13available for other Python developers to use under open source license terms.
14
15This allows Python users to share and collaborate effectively, benefiting
16from the solutions others have already created to common (and sometimes
17even rare!) problems, as well as potentially contributing their own
18solutions to the common pool.
19
20This guide covers the installation part of the process. For a guide to
21creating and sharing your own Python projects, refer to the
22:ref:`distribution guide <distributing-index>`.
23
24.. note::
25
26 For corporate and other institutional users, be aware that many
27 organisations have their own policies around using and contributing to
28 open source software. Please take such policies into account when making
29 use of the distribution and installation tools provided with Python.
30
31
32Key terms
33=========
34
35* ``pip`` is the preferred installer program. Starting with Python 2.7.9, it
36 is included by default with the Python binary installers.
37* a virtual environment is a semi-isolated Python environment that allows
38 packages to be installed for use by a particular application, rather than
39 being installed system wide
40* ``virtualenv`` is a third party tools for creating virtual environments, it
41 is defaults to installing ``pip`` into all created virtual environments.
42* the `Python Packaging Index <https://pypi.python.org/pypi>`__ is a public
43 repository of open source licensed packages made available for use by
44 other Python users
45* the `Python Packaging Authority
46 <https://packaging.python.org/en/latest/future.html>`__ are the group of
47 developers and documentation authors responsible for the maintenance and
48 evolution of the standard packaging tools and the associated metadata and
49 file format standards. They maintain a variety of tools, documentation
50 and issue trackers on both `GitHub <https://github.com/pypa>`__ and
51 `BitBucket <https://bitbucket.org/pypa/>`__.
52* ``distutils`` is the original build and distribution system first added to
53 the Python standard library in 1998. While direct use of ``distutils`` is
54 being phased out, it still laid the foundation for the current packaging
55 and distribution infrastructure, and it not only remains part of the
56 standard library, but its name lives on in other ways (such as the name
57 of the mailing list used to coordinate Python packaging standards
58 development).
59
60
61Basic usage
62===========
63
64The standard packaging tools are all designed to be used from the command
65line.
66
67The following command will install the latest version of a module and its
68dependencies from the Python Packaging Index::
69
70 python -m pip install SomePackage
71
72.. note::
73
74 For POSIX users (including Mac OS X and Linux users), the examples in
75 this guide assume the use of a :term:`virtual environment`. You may install
76 ``virtualenv`` to provide such environments using either pip
77 (``pip install virtualenv``) or through your system package manager
78 (commonly called ``virtualenv`` or ``python-virtualenv``).
79
80 For Windows users, the examples in this guide assume that the option to
81 adjust the system PATH environment variable was selected when installing
82 Python.
83
84It's also possible to specify an exact or minimum version directly on the
85command line::
86
87 python -m pip install SomePackage==1.0.4 # specific version
88 python -m pip install 'SomePackage>=1.0.4' # minimum version
89
90Normally, if a suitable module is already installed, attempting to install
91it again will have no effect. Upgrading existing modules must be requested
92explicitly::
93
94 python -m pip install --upgrade SomePackage
95
96More information and resources regarding ``pip`` and its capabilities can be
97found in the `Python Packaging User Guide <https://packaging.python.org>`__.
98
99.. seealso::
100
101 `Python Packaging User Guide: Installing Python Distribution Packages
102 <https://packaging.python.org/en/latest/installing.html#installing-python-distribution-packages>`__
103
104
105How do I ...?
106=============
107
108These are quick answers or links for some common tasks.
109
110... install ``pip`` in versions of Python prior to Python 2.7.9?
111----------------------------------------------------------------
112
113Python only started bundling ``pip`` with Python 2.7.9. For earlier versions,
114``pip`` needs to be "bootstrapped" as described in the Python Packaging
115User Guide.
116
117.. seealso::
118
119 `Python Packaging User Guide: Setup for Installing Distribution Packages
120 <https://packaging.python.org/en/latest/installing.html#setup-for-installing-distribution-packages>`__
121
122
123.. installing-per-user-installation:
124
125... install packages just for the current user?
126-----------------------------------------------
127
128Passing the ``--user`` option to ``python -m pip install`` will install a
129package just for the current user, rather than for all users of the system.
130
131
132... install scientific Python packages?
133---------------------------------------
134
135A number of scientific Python packages have complex binary dependencies, and
136aren't currently easy to install using ``pip`` directly. At this point in
137time, it will often be easier for users to install these packages by
138`other means
139<https://packaging.python.org/en/latest/science.html>`__
140rather than attempting to install them with ``pip``.
141
142.. seealso::
143
144 `Python Packaging User Guide: Installing Scientific Packages
145 <https://packaging.python.org/en/latest/science.html>`__
146
147
148... work with multiple versions of Python installed in parallel?
149----------------------------------------------------------------
150
151On Linux, Mac OS X and other POSIX systems, use the versioned Python commands
152in combination with the ``-m`` switch to run the appropriate copy of
153``pip``::
154
155 python2 -m pip install SomePackage # default Python 2
156 python2.7 -m pip install SomePackage # specifically Python 2.7
157 python3 -m pip install SomePackage # default Python 3
158 python3.4 -m pip install SomePackage # specifically Python 3.4
159
160(appropriately versioned ``pip`` commands may also be available)
161
162On Windows, use the ``py`` Python launcher in combination with the ``-m``
163switch::
164
165 py -2 -m pip install SomePackage # default Python 2
166 py -2.7 -m pip install SomePackage # specifically Python 2.7
167 py -3 -m pip install SomePackage # default Python 3
168 py -3.4 -m pip install SomePackage # specifically Python 3.4
169
170.. other questions:
171
172 Once the Development & Deployment part of PPUG is fleshed out, some of
173 those sections should be linked from new questions here (most notably,
174 we should have a question about avoiding depending on PyPI that links to
175 https://packaging.python.org/en/latest/deployment.html#pypi-mirrors-and-caches)
176
177
178Common installation issues
179==========================
180
181Installing into the system Python on Linux
182------------------------------------------
183
184On Linux systems, a Python installation will typically be included as part
185of the distribution. Installing into this Python installation requires
186root access to the system, and may interfere with the operation of the
187system package manager and other components of the system if a component
188is unexpectedly upgraded using ``pip``.
189
190On such systems, it is often better to use a virtual environment or a
191per-user installation when installing packages with ``pip``.
192
193
194Installing binary extensions
195----------------------------
196
197Python has typically relied heavily on source based distribution, with end
198users being expected to compile extension modules from source as part of
199the installation process.
200
201With the introduction of support for the binary ``wheel`` format, and the
202ability to publish wheels for at least Windows and Mac OS X through the
203Python Packaging Index, this problem is expected to diminish over time,
204as users are more regularly able to install pre-built extensions rather
205than needing to build them themselves.
206
207Some of the solutions for installing `scientific software
208<https://packaging.python.org/en/latest/science.html>`__
209that is not yet available as pre-built ``wheel`` files may also help with
210obtaining other binary extensions without needing to build them locally.
211
212.. seealso::
213
214 `Python Packaging User Guide: Binary Extensions
215 <https://packaging.python.org/en/latest/extensions.html>`__