pip/docs/html/cli/pip_install.rst

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

544 lines
17 KiB
ReStructuredText
Raw Normal View History

2014-02-12 06:55:43 +01:00
.. _`pip install`:
===========
2014-02-12 06:55:43 +01:00
pip install
===========
2014-02-12 06:55:43 +01:00
2020-02-11 14:05:28 +01:00
2014-02-12 06:55:43 +01:00
Usage
2020-02-11 14:00:03 +01:00
=====
2014-02-12 06:55:43 +01:00
2020-10-18 19:12:24 +02:00
.. tab:: Unix/macOS
.. pip-command-usage:: install 'python -m pip'
2020-10-18 19:12:24 +02:00
.. tab:: Windows
2020-10-18 19:12:24 +02:00
.. pip-command-usage:: install "py -m pip"
2014-02-12 06:55:43 +01:00
2020-02-11 14:05:28 +01:00
2014-02-12 06:55:43 +01:00
Description
2020-02-11 14:00:03 +01:00
===========
2014-02-12 06:55:43 +01:00
.. pip-command-description:: install
Overview
2020-02-11 14:00:03 +01:00
--------
2020-02-11 14:51:29 +01:00
pip install has several stages:
1. Identify the base requirements. The user supplied arguments are processed
here.
2. Resolve dependencies. What will be installed is determined here.
3. Build wheels. All the dependencies that can be are built into wheels.
4. Install the packages (and uninstall anything being upgraded/replaced).
Note that ``pip install`` prefers to leave the installed version as-is
unless ``--upgrade`` is specified.
Argument Handling
2020-02-11 14:00:03 +01:00
-----------------
When looking at the items to be installed, pip checks what type of item
each is, in the following order:
1. Project or archive URL.
2. Local directory (which must contain a ``pyproject.toml`` or ``setup.py``,
otherwise pip will report an error).
3. Local file (a sdist or wheel format archive, following the naming
conventions for those formats).
4. A requirement, as specified in :pep:`440`.
Each item identified is added to the set of requirements to be satisfied by
the install.
Working Out the Name and Version
2020-02-11 14:00:03 +01:00
--------------------------------
For each candidate item, pip needs to know the project name and version. For
wheels (identified by the ``.whl`` file extension) this can be obtained from
the filename, as per the Wheel spec. For local directories, or explicitly
specified sdist files, the ``setup.py egg_info`` command is used to determine
the project metadata. For sdists located via an index, the filename is parsed
for the name and project version (this is in theory slightly less reliable
than using the ``egg_info`` command, but avoids downloading and processing
unnecessary numbers of files).
Any URL may use the ``#egg=name`` syntax (see :doc:`../topics/vcs-support`) to
explicitly state the project name.
Satisfying Requirements
2020-02-11 14:00:03 +01:00
-----------------------
Once pip has the set of requirements to satisfy, it chooses which version of
each requirement to install using the simple rule that the latest version that
satisfies the given constraints will be installed (but see :ref:`here <Pre Release Versions>`
for an exception regarding pre-release versions). Where more than one source of
the chosen version is available, it is assumed that any source is acceptable
(as otherwise the versions would differ).
2022-07-01 18:18:34 +02:00
Obtaining information about what was installed
----------------------------------------------
The install command has a ``--report`` option that will generate a JSON report of what
pip has installed. In combination with the ``--dry-run`` and ``--ignore-installed`` it
can be used to *resolve* a set of requirements without actually installing them.
The report can be written to a file, or to standard output (using ``--report -`` in
combination with ``--quiet``).
The format of the JSON report is described in :doc:`../reference/installation-report`.
Installation Order
2020-02-11 14:00:03 +01:00
------------------
.. note::
This section is only about installation order of runtime dependencies, and
does not apply to build dependencies (those are specified using PEP 518).
2015-04-02 06:21:19 +02:00
As of v6.1.0, pip installs dependencies before their dependents, i.e. in
"topological order." This is the only commitment pip currently makes related
2015-04-02 06:21:19 +02:00
to order. While it may be coincidentally true that pip will install things in
the order of the install arguments or in the order of the items in a
requirements file, this is not a promise.
In the event of a dependency cycle (aka "circular dependency"), the current
implementation (which might possibly change later) has it such that the first
2015-04-02 06:21:19 +02:00
encountered member of the cycle is installed last.
For instance, if quux depends on foo which depends on bar which depends on baz,
which depends on foo:
2020-10-18 19:12:24 +02:00
.. tab:: Unix/macOS
2020-10-18 19:12:24 +02:00
.. code-block:: console
2020-10-18 19:12:24 +02:00
$ python -m pip install quux
...
Installing collected packages baz, bar, foo, quux
2020-10-18 19:12:24 +02:00
$ python -m pip install bar
...
Installing collected packages foo, baz, bar
2020-10-18 19:12:24 +02:00
.. tab:: Windows
2020-10-18 19:12:24 +02:00
.. code-block:: console
2020-10-18 19:12:24 +02:00
C:\> py -m pip install quux
...
Installing collected packages baz, bar, foo, quux
2020-10-18 19:12:24 +02:00
C:\> py -m pip install bar
...
Installing collected packages foo, baz, bar
2015-04-02 01:57:15 +02:00
2015-04-02 06:21:19 +02:00
Prior to v6.1.0, pip made no commitments about install order.
The decision to install topologically is based on the principle that
installations should proceed in a way that leaves the environment usable at each
step. This has two main practical benefits:
1. Concurrent use of the environment during the install is more likely to work.
2. A failed install is less likely to leave a broken environment. Although pip
would like to support failure rollbacks eventually, in the mean time, this is
an improvement.
2015-04-02 06:21:19 +02:00
Although the new install order is not intended to replace (and does not replace)
the use of ``setup_requires`` to declare build dependencies, it may help certain
projects install from sdist (that might previously fail) that fit the following
profile:
1. They have build dependencies that are also declared as install dependencies
using ``install_requires``.
2. ``python setup.py egg_info`` works without their build dependencies being
installed.
3. For whatever reason, they don't or won't declare their build dependencies using
``setup_requires``.
.. _`0-requirements-file-format`:
.. rubric:: Requirements File Format
2014-02-12 06:55:43 +01:00
This section has been moved to :doc:`../reference/requirements-file-format`.
2015-06-25 00:58:10 +02:00
.. _`0-requirement-specifiers`:
.. rubric:: Requirement Specifiers
2014-02-12 06:55:43 +01:00
This section has been moved to :doc:`../reference/requirement-specifiers`.
2014-02-12 06:55:43 +01:00
.. _`0-per-requirement-overrides`:
.. rubric:: Per-requirement Overrides
This is now covered in :doc:`../reference/requirements-file-format`.
2014-02-12 06:55:43 +01:00
.. _`Pre Release Versions`:
Pre-release Versions
2020-02-11 14:00:03 +01:00
--------------------
2014-02-12 06:55:43 +01:00
Starting with v1.4, pip will only install stable versions as specified by
`pre-releases`_ by default. If a version cannot be parsed as a compliant :pep:`440`
2014-02-12 06:55:43 +01:00
version then it is assumed to be a pre-release.
If a Requirement specifier includes a pre-release or development version
(e.g. ``>=0.0.dev0``) then pip will allow pre-release and development versions
for that requirement. This does not include the != flag.
The ``pip install`` command also supports a :ref:`--pre <install_--pre>` flag
that enables installation of pre-releases and development releases.
2014-02-12 06:55:43 +01:00
2018-06-05 16:10:25 +02:00
.. _pre-releases: https://www.python.org/dev/peps/pep-0440/#handling-of-pre-releases
2014-02-12 06:55:43 +01:00
.. _`0-vcs-support`:
.. rubric:: VCS Support
2014-02-12 06:55:43 +01:00
This is now covered in :doc:`../topics/vcs-support`.
2014-02-12 06:55:43 +01:00
Finding Packages
2020-02-11 14:00:03 +01:00
----------------
2014-02-12 06:55:43 +01:00
pip searches for packages on `PyPI`_ using the
`HTTP simple interface <https://pypi.org/simple/>`_,
2021-09-05 06:24:08 +02:00
which is documented `here <https://packaging.python.org/specifications/simple-repository-api/>`_
and `there <https://www.python.org/dev/peps/pep-0503/>`_.
2014-02-12 06:55:43 +01:00
pip offers a number of package index options for modifying how packages are
found.
2014-02-12 06:55:43 +01:00
pip looks for packages in a number of places: on PyPI (if not disabled via
``--no-index``), in the local filesystem, and in any additional repositories
specified via ``--find-links`` or ``--index-url``. There is no ordering in
the locations that are searched. Rather they are all checked, and the "best"
match for the requirements (in terms of version number - see :pep:`440` for
details) is selected.
2014-02-12 06:55:43 +01:00
See the :ref:`pip install Examples<pip install Examples>`.
.. _`0-ssl certificate verification`:
.. rubric:: SSL Certificate Verification
2014-02-12 06:55:43 +01:00
This is now covered in :doc:`../topics/https-certificates`.
2014-02-12 06:55:43 +01:00
.. _`0-caching`:
.. rubric:: Caching
2021-08-06 15:06:36 +02:00
This is now covered in :doc:`../topics/caching`.
.. _`0-wheel-cache`:
.. rubric:: Wheel Cache
2021-08-06 15:06:36 +02:00
This is now covered in :doc:`../topics/caching`.
.. _`0-hash-checking-mode`:
.. rubric:: Hash checking mode
2014-02-12 06:55:43 +01:00
This is now covered in :doc:`../topics/secure-installs`.
2014-02-12 06:55:43 +01:00
.. _`0-local-project-installs`:
.. rubric:: Local Project Installs
This is now covered in :doc:`../topics/local-project-installs`.
2019-08-03 19:31:42 +02:00
.. _`0-editable-installs`:
.. rubric:: Editable installs
2014-02-12 06:55:43 +01:00
This is now covered in :doc:`../topics/local-project-installs`.
2014-02-12 06:55:43 +01:00
.. _`0-build-system-interface`:
.. rubric:: Build System Interface
This is now covered in :doc:`../reference/build-system/index`.
2014-04-09 07:57:22 +02:00
.. _`pip install Options`:
2014-02-12 06:55:43 +01:00
Options
2020-02-11 14:00:03 +01:00
=======
2014-02-12 06:55:43 +01:00
.. pip-command-options:: install
.. pip-index-options:: install
2014-02-12 06:55:43 +01:00
.. _`pip install Examples`:
2020-02-11 14:05:56 +01:00
2014-02-12 06:55:43 +01:00
Examples
2020-02-11 14:00:03 +01:00
========
2014-02-12 06:55:43 +01:00
#. Install ``SomePackage`` and its dependencies from `PyPI`_ using :ref:`Requirement Specifiers`
2014-02-12 06:55:43 +01:00
2020-10-18 19:12:24 +02:00
.. tab:: Unix/macOS
2020-10-18 19:12:24 +02:00
.. code-block:: shell
2014-02-12 06:55:43 +01:00
2020-10-18 19:12:24 +02:00
python -m pip install SomePackage # latest version
python -m pip install 'SomePackage==1.0.4' # specific version
2020-10-18 19:12:24 +02:00
python -m pip install 'SomePackage>=1.0.4' # minimum version
2020-10-18 19:12:24 +02:00
.. tab:: Windows
2020-10-18 19:12:24 +02:00
.. code-block:: shell
2020-10-18 19:12:24 +02:00
py -m pip install SomePackage # latest version
py -m pip install "SomePackage==1.0.4" # specific version
py -m pip install "SomePackage>=1.0.4" # minimum version
2014-02-12 06:55:43 +01:00
#. Install a list of requirements specified in a file. See the :ref:`Requirements files <Requirements Files>`.
2014-02-12 06:55:43 +01:00
2020-10-18 19:12:24 +02:00
.. tab:: Unix/macOS
2014-02-12 06:55:43 +01:00
2020-10-18 19:12:24 +02:00
.. code-block:: shell
2020-10-18 19:12:24 +02:00
python -m pip install -r requirements.txt
2020-10-18 19:12:24 +02:00
.. tab:: Windows
2020-10-18 19:12:24 +02:00
.. code-block:: shell
2020-10-18 19:12:24 +02:00
py -m pip install -r requirements.txt
2014-02-12 06:55:43 +01:00
#. Upgrade an already installed ``SomePackage`` to the latest from PyPI.
2014-02-12 06:55:43 +01:00
2020-10-18 19:12:24 +02:00
.. tab:: Unix/macOS
2020-10-18 19:12:24 +02:00
.. code-block:: shell
2020-10-18 19:12:24 +02:00
python -m pip install --upgrade SomePackage
2020-10-18 19:12:24 +02:00
.. tab:: Windows
2014-02-12 06:55:43 +01:00
2020-10-18 19:12:24 +02:00
.. code-block:: shell
2020-10-18 19:12:24 +02:00
py -m pip install --upgrade SomePackage
2014-02-12 06:55:43 +01:00
.. note::
2021-03-05 17:58:38 +01:00
This will guarantee an update to ``SomePackage`` as it is a direct
requirement, and possibly upgrade dependencies if their installed
versions do not meet the minimum requirements of ``SomePackage``.
Any non-requisite updates of its dependencies (indirect requirements)
will be affected by the ``--upgrade-strategy`` command.
2014-02-12 06:55:43 +01:00
#. Install a local project in "editable" mode. See the section on :ref:`Editable Installs <editable-installs>`.
2014-02-12 06:55:43 +01:00
2020-10-18 19:12:24 +02:00
.. tab:: Unix/macOS
2020-10-18 19:12:24 +02:00
.. code-block:: shell
2020-10-18 19:12:24 +02:00
python -m pip install -e . # project in current directory
python -m pip install -e path/to/project # project in another directory
2020-10-18 19:12:24 +02:00
.. tab:: Windows
2014-02-12 06:55:43 +01:00
2020-10-18 19:12:24 +02:00
.. code-block:: shell
2020-10-18 19:12:24 +02:00
py -m pip install -e . # project in current directory
py -m pip install -e path/to/project # project in another directory
2014-02-12 06:55:43 +01:00
2020-07-17 22:07:32 +02:00
#. Install a project from VCS
2020-10-18 19:12:24 +02:00
.. tab:: Unix/macOS
2020-10-18 19:12:24 +02:00
.. code-block:: shell
python -m pip install 'SomeProject@git+https://git.repo/some_pkg.git@1.3.1'
2020-07-17 22:07:32 +02:00
2020-10-18 19:12:24 +02:00
.. tab:: Windows
2020-10-18 19:12:24 +02:00
.. code-block:: shell
py -m pip install "SomeProject@git+https://git.repo/some_pkg.git@1.3.1"
2020-07-17 22:07:32 +02:00
#. Install a project from VCS in "editable" mode. See the sections on :doc:`../topics/vcs-support` and :ref:`Editable Installs <editable-installs>`.
2014-02-12 06:55:43 +01:00
2020-10-18 19:12:24 +02:00
.. tab:: Unix/macOS
2020-10-18 19:12:24 +02:00
.. code-block:: shell
python -m pip install -e 'git+https://git.repo/some_pkg.git#egg=SomePackage' # from git
python -m pip install -e 'hg+https://hg.repo/some_pkg.git#egg=SomePackage' # from mercurial
python -m pip install -e 'svn+svn://svn.repo/some_pkg/trunk/#egg=SomePackage' # from svn
python -m pip install -e 'git+https://git.repo/some_pkg.git@feature#egg=SomePackage' # from 'feature' branch
python -m pip install -e 'git+https://git.repo/some_repo.git#egg=subdir&subdirectory=subdir_path' # install a python package from a repo subdirectory
2020-10-18 19:12:24 +02:00
.. tab:: Windows
2020-10-18 19:12:24 +02:00
.. code-block:: shell
2014-02-12 06:55:43 +01:00
py -m pip install -e "git+https://git.repo/some_pkg.git#egg=SomePackage" # from git
py -m pip install -e "hg+https://hg.repo/some_pkg.git#egg=SomePackage" # from mercurial
py -m pip install -e "svn+svn://svn.repo/some_pkg/trunk/#egg=SomePackage" # from svn
py -m pip install -e "git+https://git.repo/some_pkg.git@feature#egg=SomePackage" # from 'feature' branch
2020-10-18 19:12:24 +02:00
py -m pip install -e "git+https://git.repo/some_repo.git#egg=subdir&subdirectory=subdir_path" # install a python package from a repo subdirectory
2014-02-12 06:55:43 +01:00
#. Install a package with `extras`_.
2014-02-12 06:55:43 +01:00
2020-10-18 19:12:24 +02:00
.. tab:: Unix/macOS
2020-10-18 19:12:24 +02:00
.. code-block:: shell
python -m pip install 'SomePackage[PDF]'
python -m pip install 'SomePackage[PDF] @ git+https://git.repo/SomePackage@main#subdirectory=subdir_path'
python -m pip install '.[PDF]' # project in current directory
python -m pip install 'SomePackage[PDF]==3.0'
python -m pip install 'SomePackage[PDF,EPUB]' # multiple extras
2020-10-18 19:12:24 +02:00
.. tab:: Windows
2020-10-18 19:12:24 +02:00
.. code-block:: shell
2014-02-12 06:55:43 +01:00
py -m pip install "SomePackage[PDF]"
py -m pip install "SomePackage[PDF] @ git+https://git.repo/SomePackage@main#subdirectory=subdir_path"
py -m pip install ".[PDF]" # project in current directory
py -m pip install "SomePackage[PDF]==3.0"
py -m pip install "SomePackage[PDF,EPUB]" # multiple extras
2014-02-12 06:55:43 +01:00
#. Install a particular source archive file.
2014-02-12 06:55:43 +01:00
2020-10-18 19:12:24 +02:00
.. tab:: Unix/macOS
2020-10-18 19:12:24 +02:00
.. code-block:: shell
python -m pip install './downloads/SomePackage-1.0.4.tar.gz'
python -m pip install 'http://my.package.repo/SomePackage-1.0.4.zip'
2020-10-18 19:12:24 +02:00
.. tab:: Windows
2014-02-12 06:55:43 +01:00
2020-10-18 19:12:24 +02:00
.. code-block:: shell
2014-02-12 06:55:43 +01:00
py -m pip install "./downloads/SomePackage-1.0.4.tar.gz"
py -m pip install "http://my.package.repo/SomePackage-1.0.4.zip"
2014-02-12 06:55:43 +01:00
#. Install a particular source archive file following :pep:`440` direct references.
2020-10-18 19:12:24 +02:00
.. tab:: Unix/macOS
2020-10-18 19:12:24 +02:00
.. code-block:: shell
python -m pip install 'SomeProject@http://my.package.repo/SomeProject-1.2.3-py33-none-any.whl'
python -m pip install 'SomeProject @ http://my.package.repo/SomeProject-1.2.3-py33-none-any.whl'
python -m pip install 'SomeProject@http://my.package.repo/1.2.3.tar.gz'
2020-10-18 19:12:24 +02:00
.. tab:: Windows
2020-10-18 19:12:24 +02:00
.. code-block:: shell
py -m pip install "SomeProject@http://my.package.repo/SomeProject-1.2.3-py33-none-any.whl"
2020-10-18 19:12:24 +02:00
py -m pip install "SomeProject @ http://my.package.repo/SomeProject-1.2.3-py33-none-any.whl"
py -m pip install "SomeProject@http://my.package.repo/1.2.3.tar.gz"
#. Install from alternative package repositories.
2014-02-12 06:55:43 +01:00
Install from a different index, and not `PyPI`_
2020-10-18 19:12:24 +02:00
.. tab:: Unix/macOS
2020-10-18 19:12:24 +02:00
.. code-block:: shell
2014-02-12 06:55:43 +01:00
2020-10-18 19:12:24 +02:00
python -m pip install --index-url http://my.package.repo/simple/ SomePackage
2014-02-12 06:55:43 +01:00
2020-10-18 19:12:24 +02:00
.. tab:: Windows
2014-02-12 06:55:43 +01:00
2020-10-18 19:12:24 +02:00
.. code-block:: shell
2014-02-12 06:55:43 +01:00
2020-10-18 19:12:24 +02:00
py -m pip install --index-url http://my.package.repo/simple/ SomePackage
Install from a local flat directory containing archives (and don't scan indexes):
2020-10-18 19:12:24 +02:00
.. tab:: Unix/macOS
2020-10-18 19:12:24 +02:00
.. code-block:: shell
python -m pip install --no-index --find-links=file:///local/dir/ SomePackage
python -m pip install --no-index --find-links=/local/dir/ SomePackage
python -m pip install --no-index --find-links=relative/dir/ SomePackage
2020-10-18 19:12:24 +02:00
.. tab:: Windows
2020-10-18 19:12:24 +02:00
.. code-block:: shell
py -m pip install --no-index --find-links=file:///local/dir/ SomePackage
py -m pip install --no-index --find-links=/local/dir/ SomePackage
py -m pip install --no-index --find-links=relative/dir/ SomePackage
Search an additional index during install, in addition to `PyPI`_
.. warning::
Using this option to search for packages which are not in the main
repository (such as private packages) is unsafe, per a security
vulnerability called
`dependency confusion <https://azure.microsoft.com/en-us/resources/3-ways-to-mitigate-risk-using-private-package-feeds/>`_:
an attacker can claim the package on the public repository in a way that
will ensure it gets chosen over the private package.
2020-10-18 19:12:24 +02:00
.. tab:: Unix/macOS
2020-10-18 19:12:24 +02:00
.. code-block:: shell
python -m pip install --extra-index-url http://my.package.repo/simple SomePackage
2020-10-18 19:12:24 +02:00
.. tab:: Windows
2020-10-18 19:12:24 +02:00
.. code-block:: shell
py -m pip install --extra-index-url http://my.package.repo/simple SomePackage
2014-02-12 06:55:43 +01:00
#. Find pre-release and development versions, in addition to stable versions. By default, pip only finds stable versions.
2014-02-12 06:55:43 +01:00
2020-10-18 19:12:24 +02:00
.. tab:: Unix/macOS
2020-10-18 19:12:24 +02:00
.. code-block:: shell
2020-10-18 19:12:24 +02:00
python -m pip install --pre SomePackage
2020-10-18 19:12:24 +02:00
.. tab:: Windows
2020-10-18 19:12:24 +02:00
.. code-block:: shell
2020-10-18 19:12:24 +02:00
py -m pip install --pre SomePackage
#. Install packages from source.
Do not use any binary packages
2020-10-18 19:12:24 +02:00
.. tab:: Unix/macOS
2020-10-18 19:12:24 +02:00
.. code-block:: shell
2020-10-18 19:12:24 +02:00
python -m pip install SomePackage1 SomePackage2 --no-binary :all:
2020-10-18 19:12:24 +02:00
.. tab:: Windows
2020-10-18 19:12:24 +02:00
.. code-block:: shell
2020-10-18 19:12:24 +02:00
py -m pip install SomePackage1 SomePackage2 --no-binary :all:
Specify ``SomePackage1`` to be installed from source:
2020-10-18 19:12:24 +02:00
.. tab:: Unix/macOS
2020-10-18 19:12:24 +02:00
.. code-block:: shell
2020-10-18 19:12:24 +02:00
python -m pip install SomePackage1 SomePackage2 --no-binary SomePackage1
2020-10-18 19:12:24 +02:00
.. tab:: Windows
2020-10-18 19:12:24 +02:00
.. code-block:: shell
2020-10-18 19:12:24 +02:00
py -m pip install SomePackage1 SomePackage2 --no-binary SomePackage1
.. _extras: https://www.python.org/dev/peps/pep-0508/#extras
.. _PyPI: https://pypi.org/