Movatterモバイル変換


[0]ホーム

URL:


ContentsMenuExpandLight modeDark modeAuto light/dark, in light modeAuto light/dark, in dark modeSkip to content
pip documentation v25.2
pip documentation v25.2

Project

Back to top

pip install

Usage

python-mpipinstall[options]<requirementspecifier>[package-index-options]...python-mpipinstall[options]-r<requirementsfile>[package-index-options]...python-mpipinstall[options][-e]<vcsprojecturl>...python-mpipinstall[options][-e]<localprojectpath>...python-mpipinstall[options]<archiveurl/path>...
py-mpipinstall[options]<requirementspecifier>[package-index-options]...py-mpipinstall[options]-r<requirementsfile>[package-index-options]...py-mpipinstall[options][-e]<vcsprojecturl>...py-mpipinstall[options][-e]<localprojectpath>...py-mpipinstall[options]<archiveurl/path>...

Description

Install packages from:

  • PyPI (and other indexes) using requirement specifiers.

  • VCS project urls.

  • Local project directories.

  • Local or remote source archives.

pip also supports installing from “requirements files”, which providean easy way to specify a whole environment to be installed.

Overview

pip install has several stages:

  1. Identify the base requirements. The user supplied arguments are processedhere.

  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 thatpipinstall prefers to leave the installed version as-isunless--upgrade is specified.

Argument Handling

When looking at the items to be installed, pip checks what type of itemeach is, in the following order:

  1. Project or archive URL.

  2. Local directory (which must contain apyproject.toml orsetup.py,otherwise pip will report an error).

  3. Local file (a sdist or wheel format archive, following the namingconventions for those formats).

  4. Aversion specifier.

Each item identified is added to the set of requirements to be satisfied bythe install.

Working Out the Name and Version

For each candidate item, pip needs to know the project name and version. Forwheels (identified by the.whl file extension) this can be obtained fromthe filename, as per the Wheel spec. For local directories, or explicitlyspecified sdist files, thesetup.pyegg_info command is used to determinethe project metadata. For sdists located via an index, the filename is parsedfor the name and project version (this is in theory slightly less reliablethan using theegg_info command, but avoids downloading and processingunnecessary numbers of files).

Any URL may use the#egg=name syntax (seeVCS Support) toexplicitly state the project name.

Satisfying Requirements

Once pip has the set of requirements to satisfy, it chooses which version ofeach requirement to install using the simple rule that the latest version thatsatisfies the given constraints will be installed (but seeherefor an exception regarding pre-release versions). Where more than one source ofthe chosen version is available, it is assumed that any source is acceptable(as otherwise the versions would differ).

Obtaining information about what was installed

The install command has a--report option that will generate a JSON report of whatpip has installed. In combination with the--dry-run and--ignore-installed itcan be used toresolve a set of requirements without actually installing them.

The report can be written to a file, or to standard output (using--report- incombination with--quiet).

The format of the JSON report is described inInstallation Report.

Installation Order

Note

This section is only about installation order of runtime dependencies, anddoes not apply to build dependencies (those are specified using the[build-system] table).

As of v6.1.0, pip installs dependencies before their dependents, i.e. in“topological order.” This is the only commitment pip currently makes relatedto order. While it may be coincidentally true that pip will install things inthe order of the install arguments or in the order of the items in arequirements file, this is not a promise.

In the event of a dependency cycle (aka “circular dependency”), the currentimplementation (which might possibly change later) has it such that the firstencountered 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:

$python-mpipinstallquux...Installing collected packages baz, bar, foo, quux$python-mpipinstallbar...Installing collected packages foo, baz, bar
C:\> py -m pip install quux...Installing collected packages baz, bar, foo, quuxC:\> py -m pip install bar...Installing collected packages foo, baz, bar

Prior to v6.1.0, pip made no commitments about install order.

The decision to install topologically is based on the principle thatinstallations should proceed in a way that leaves the environment usable at eachstep. 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 pipwould like to support failure rollbacks eventually, in the mean time, this isan improvement.

Although the new install order is not intended to replace (and does not replace)the use ofsetup_requires to declare build dependencies, it may help certainprojects install from sdist (that might previously fail) that fit the followingprofile:

  1. They have build dependencies that are also declared as install dependenciesusinginstall_requires.

  2. pythonsetup.pyegg_info works without their build dependencies beinginstalled.

  3. For whatever reason, they don’t or won’t declare their build dependencies usingsetup_requires.

Requirements File Format

This section has been moved toRequirements File Format.

Requirement Specifiers

This section has been moved toRequirement Specifiers.

Per-requirement Overrides

This is now covered inRequirements File Format.

Pre-release Versions

Starting with v1.4, pip will only install stable versions as specified bypre-releases by default. If a version cannot be parsed as acompliant version then it is assumed to bea 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 versionsfor that requirement. This does not include the != flag.

Thepipinstall command also supports a--pre flagthat enables installation of pre-releases and development releases.

VCS Support

This is now covered inVCS Support.

Finding Packages

pip searches for packages onPyPI using theHTTP simple interface,which is documentedhereandthere.

pip offers a number of package index options for modifying how packages arefound.

pip looks for packages in a number of places: on PyPI (or the index given as--index-url, if not disabled via--no-index), in the local filesystem,and in any additional repositories specified via--find-links or--extra-index-url. There is no priority in the locations that are searched.Rather they are all checked, and the “best” match for the requirements (interms of version number - see thespecification for details) is selected.

See thepip install Examples.

SSL Certificate Verification

This is now covered inHTTPS Certificates.

Caching

This is now covered inCaching.

Wheel Cache

This is now covered inCaching.

Hash checking mode

This is now covered inSecure installs.

Local Project Installs

This is now covered inLocal project installs.

Editable installs

This is now covered inLocal project installs.

Build System Interface

This is now covered inBuild System Interface.

Options

-r,--requirement<file>

Install from the given requirements file. This option can be used multiple times.

(environment variable:PIP_REQUIREMENT)

-c,--constraint<file>

Constrain versions using the given constraints file. This option can be used multiple times.

(environment variable:PIP_CONSTRAINT)

--no-deps

Don’t install package dependencies.

(environment variable:PIP_NO_DEPS,PIP_NO_DEPENDENCIES)

--pre

Include pre-release and development versions. By default, pip only finds stable versions.

(environment variable:PIP_PRE)

-e,--editable<path/url>

Install a project in editable mode (i.e. setuptools “develop mode”) from a local project path or a VCS url.

(environment variable:PIP_EDITABLE)

--dry-run

Don’t actually install anything, just print what would be. Can be used in combination with --ignore-installed to ‘resolve’ the requirements.

(environment variable:PIP_DRY_RUN)

-t,--target<dir>

Install packages into <dir>. By default this will not replace existing files/folders in <dir>. Use --upgrade to replace existing packages in <dir> with new versions.

(environment variable:PIP_TARGET)

--platform<platform>

Only use wheels compatible with <platform>. Defaults to the platform of the running system. Use this option multiple times to specify multiple platforms supported by the target interpreter.

(environment variable:PIP_PLATFORM)

--python-version<python_version>

The Python interpreter version to use for wheel and “Requires-Python”compatibility checks. Defaults to a version derived from the runninginterpreter. The version can be specified using up to three dot-separatedintegers (e.g. “3” for 3.0.0, “3.7” for 3.7.0, or “3.7.3”). A major-minorversion can also be given as a string without dots (e.g. “37” for 3.7.0).

(environment variable:PIP_PYTHON_VERSION)

--implementation<implementation>

Only use wheels compatible with Python implementation <implementation>, e.g. ‘pp’, ‘jy’, ‘cp’, or ‘ip’. If not specified, then the current interpreter implementation is used. Use ‘py’ to force implementation-agnostic wheels.

(environment variable:PIP_IMPLEMENTATION)

--abi<abi>

Only use wheels compatible with Python abi <abi>, e.g. ‘pypy_41’. If not specified, then the current interpreter abi tag is used. Use this option multiple times to specify multiple abis supported by the target interpreter. Generally you will need to specify --implementation, --platform, and --python-version when using this option.

(environment variable:PIP_ABI)

--user

Install to the Python user install directory for your platform. Typically ~/.local/, or %APPDATA%Python on Windows. (See the Python documentation for site.USER_BASE for full details.)

(environment variable:PIP_USER)

--root<dir>

Install everything relative to this alternate root directory.

(environment variable:PIP_ROOT)

--prefix<dir>

Installation prefix where lib, bin and other top-level folders are placed. Note that the resulting installation may contain scripts and other resources which reference the Python interpreter of pip, and not that of--prefix. See also the--python option if the intention is to install packages into another (possibly pip-free) environment.

(environment variable:PIP_PREFIX)

--src<dir>

Directory to check out editable projects into. The default in a virtualenv is “<venv path>/src”. The default for global installs is “<current dir>/src”.

(environment variable:PIP_SRC,PIP_SOURCE,PIP_SOURCE_DIR,PIP_SOURCE_DIRECTORY)

-U,--upgrade

Upgrade all specified packages to the newest available version. The handling of dependencies depends on the upgrade-strategy used.

(environment variable:PIP_UPGRADE)

--upgrade-strategy<upgrade_strategy>

Determines how dependency upgrading should be handled [default: only-if-needed]. “eager” - dependencies are upgraded regardless of whether the currently installed version satisfies the requirements of the upgraded package(s). “only-if-needed” - are upgraded only when they do not satisfy the requirements of the upgraded package(s).

(environment variable:PIP_UPGRADE_STRATEGY)

--force-reinstall

Reinstall all packages even if they are already up-to-date.

(environment variable:PIP_FORCE_REINSTALL)

-I,--ignore-installed

Ignore the installed packages, overwriting them. This can break your system if the existing package is of a different version or was installed with a different package manager!

(environment variable:PIP_IGNORE_INSTALLED)

--ignore-requires-python

Ignore the Requires-Python information.

(environment variable:PIP_IGNORE_REQUIRES_PYTHON)

--no-build-isolation

Disable isolation when building a modern source distribution. Build dependencies specified by PEP 518 must be already installed if this option is used.

(environment variable:PIP_NO_BUILD_ISOLATION)

--use-pep517

Use PEP 517 for building source distributions (use --no-use-pep517 to force legacy behaviour).

(environment variable:PIP_USE_PEP517)

--check-build-dependencies

Check the build dependencies when PEP517 is used.

(environment variable:PIP_CHECK_BUILD_DEPENDENCIES)

--break-system-packages

Allow pip to modify an EXTERNALLY-MANAGED Python installation

(environment variable:PIP_BREAK_SYSTEM_PACKAGES)

-C,--config-settings<settings>

Configuration settings to be passed to the PEP 517 build backend. Settings take the form KEY=VALUE. Use multiple --config-settings options to pass multiple keys to the backend.

(environment variable:PIP_CONFIG_SETTINGS)

--global-option<options>

Extra global options to be supplied to the setup.py call before the install or bdist_wheel command.

(environment variable:PIP_GLOBAL_OPTION)

--compile

Compile Python source files to bytecode

(environment variable:PIP_COMPILE)

--no-compile

Do not compile Python source files to bytecode

(environment variable:PIP_NO_COMPILE)

--no-warn-script-location

Do not warn when installing scripts outside PATH

(environment variable:PIP_NO_WARN_SCRIPT_LOCATION)

--no-warn-conflicts

Do not warn about broken dependencies

(environment variable:PIP_NO_WARN_CONFLICTS)

--no-binary<format_control>

Do not use binary packages. Can be supplied multiple times, and each time adds to the existing value. Accepts either “:all:” to disable all binary packages, “:none:” to empty the set (notice the colons), or one or more package names with commas between them (no colons). Note that some packages are tricky to compile and may fail to install when this option is used on them.

(environment variable:PIP_NO_BINARY)

--only-binary<format_control>

Do not use source packages. Can be supplied multiple times, and each time adds to the existing value. Accepts either “:all:” to disable all source packages, “:none:” to empty the set, or one or more package names with commas between them. Packages without binary distributions will fail to install when this option is used on them.

(environment variable:PIP_ONLY_BINARY)

--prefer-binary

Prefer binary packages over source packages, even if the source packages are newer.

(environment variable:PIP_PREFER_BINARY)

--require-hashes

Require a hash to check each requirement against, for repeatable installs. This option is implied when any package in a requirements file has a --hash option.

(environment variable:PIP_REQUIRE_HASHES)

--progress-bar<progress_bar>

Specify whether the progress bar should be used. In ‘auto’ mode, --quiet will suppress all progress bars. [auto, on, off, raw] (default: auto)

(environment variable:PIP_PROGRESS_BAR)

--root-user-action<root_user_action>

Action if pip is run as a root user [warn, ignore] (default: warn)

(environment variable:PIP_ROOT_USER_ACTION)

--report<file>

Generate a JSON file describing what pip did to install the provided requirements. Can be used in combination with --dry-run and --ignore-installed to ‘resolve’ the requirements. When - is used as file name it writes to stdout. When writing to stdout, please combine with the --quiet option to avoid mixing pip logging output with JSON output.

(environment variable:PIP_REPORT)

--group<[path:]group>

Install a named dependency-group from a “pyproject.toml” file. If a path is given, the name of the file must be “pyproject.toml”. Defaults to using “pyproject.toml” in the current directory.

(environment variable:PIP_GROUP)

--no-clean

Don’t clean up build directories.

(environment variable:PIP_NO_CLEAN)

-i,--index-url<url>

Base URL of the Python Package Index (defaulthttps://pypi.org/simple). This should point to a repository compliant with PEP 503 (the simple repository API) or a local directory laid out in the same format.

(environment variable:PIP_INDEX_URL,PIP_PYPI_URL)

--extra-index-url<url>

Extra URLs of package indexes to use in addition to --index-url. Should follow the same rules as --index-url.

(environment variable:PIP_EXTRA_INDEX_URL)

--no-index

Ignore package index (only looking at --find-links URLs instead).

(environment variable:PIP_NO_INDEX)

-f,--find-links<url>

If a URL or path to an html file, then parse for links to archives such as sdist (.tar.gz) or wheel (.whl) files. If a local path orfile:// URL that’s a directory, then look for archives in the directory listing. Links to VCS project URLs are not supported.

(environment variable:PIP_FIND_LINKS)

Examples

  1. InstallSomePackage and its dependencies fromPyPI usingRequirement Specifiers

    python-mpipinstallSomePackage# latest versionpython-mpipinstall'SomePackage==1.0.4'# specific versionpython-mpipinstall'SomePackage>=1.0.4'# minimum version
    py-mpipinstallSomePackage# latest versionpy-mpipinstall"SomePackage==1.0.4"# specific versionpy-mpipinstall"SomePackage>=1.0.4"# minimum version
  2. Install a list of requirements specified in a file. See theRequirements files.

    python-mpipinstall-rrequirements.txt
    py-mpipinstall-rrequirements.txt
  3. Upgrade an already installedSomePackage to the latest from PyPI.

    python-mpipinstall--upgradeSomePackage
    py-mpipinstall--upgradeSomePackage

    Note

    This will guarantee an update toSomePackage as it is a directrequirement, and possibly upgrade dependencies if their installedversions do not meet the minimum requirements ofSomePackage.Any non-requisite updates of its dependencies (indirect requirements)will be affected by the--upgrade-strategy command.

  4. Install a local project in “editable” mode. See the section onEditable Installs.

    python-mpipinstall-e.# project in current directorypython-mpipinstall-epath/to/project# project in another directory
    py-mpipinstall-e.# project in current directorypy-mpipinstall-epath/to/project# project in another directory
  5. Install a project from VCS

    python-mpipinstall'SomeProject@git+https://git.repo/some_pkg.git@1.3.1'
    py-mpipinstall"SomeProject@git+https://git.repo/some_pkg.git@1.3.1"
  6. Install a project from VCS in “editable” mode. See the sections onVCS Support andEditable Installs.

    python-mpipinstall-e'git+https://git.repo/some_pkg.git#egg=SomePackage'# from gitpython-mpipinstall-e'hg+https://hg.repo/some_pkg.git#egg=SomePackage'# from mercurialpython-mpipinstall-e'svn+svn://svn.repo/some_pkg/trunk/#egg=SomePackage'# from svnpython-mpipinstall-e'git+https://git.repo/some_pkg.git@feature#egg=SomePackage'# from 'feature' branchpython-mpipinstall-e'git+https://git.repo/some_repo.git#egg=subdir&subdirectory=subdir_path'# install a python package from a repo subdirectory
    py-mpipinstall-e"git+https://git.repo/some_pkg.git#egg=SomePackage"# from gitpy-mpipinstall-e"hg+https://hg.repo/some_pkg.git#egg=SomePackage"# from mercurialpy-mpipinstall-e"svn+svn://svn.repo/some_pkg/trunk/#egg=SomePackage"# from svnpy-mpipinstall-e"git+https://git.repo/some_pkg.git@feature#egg=SomePackage"# from 'feature' branchpy-mpipinstall-e"git+https://git.repo/some_repo.git#egg=subdir&subdirectory=subdir_path"# install a python package from a repo subdirectory
  7. Install a package with extras, i.e., optional dependencies(specification).

    python-mpipinstall'SomePackage[PDF]'python-mpipinstall'SomePackage[PDF] @ git+https://git.repo/SomePackage@main#subdirectory=subdir_path'python-mpipinstall'.[PDF]'# project in current directorypython-mpipinstall'SomePackage[PDF]==3.0'python-mpipinstall'SomePackage[PDF,EPUB]'# multiple extras
    py-mpipinstall"SomePackage[PDF]"py-mpipinstall"SomePackage[PDF] @ git+https://git.repo/SomePackage@main#subdirectory=subdir_path"py-mpipinstall".[PDF]"# project in current directorypy-mpipinstall"SomePackage[PDF]==3.0"py-mpipinstall"SomePackage[PDF,EPUB]"# multiple extras
  8. Install a particular source archive file.

    python-mpipinstall'./downloads/SomePackage-1.0.4.tar.gz'python-mpipinstall'http://my.package.repo/SomePackage-1.0.4.zip'
    py-mpipinstall"./downloads/SomePackage-1.0.4.tar.gz"py-mpipinstall"http://my.package.repo/SomePackage-1.0.4.zip"
  9. Install a particular source archive file following direct references(specification).

    python-mpipinstall'SomeProject@http://my.package.repo/SomeProject-1.2.3-py33-none-any.whl'python-mpipinstall'SomeProject @ http://my.package.repo/SomeProject-1.2.3-py33-none-any.whl'python-mpipinstall'SomeProject@http://my.package.repo/1.2.3.tar.gz'
    py-mpipinstall"SomeProject@http://my.package.repo/SomeProject-1.2.3-py33-none-any.whl"py-mpipinstall"SomeProject @ http://my.package.repo/SomeProject-1.2.3-py33-none-any.whl"py-mpipinstall"SomeProject@http://my.package.repo/1.2.3.tar.gz"
  10. Install from alternative package repositories.

    Install from a different index, and notPyPI

    python-mpipinstall--index-urlhttp://my.package.repo/simple/SomePackage
    py-mpipinstall--index-urlhttp://my.package.repo/simple/SomePackage

    Install from a local flat directory containing archives (and don’t scan indexes):

    python-mpipinstall--no-index--find-links=file:///local/dir/SomePackagepython-mpipinstall--no-index--find-links=/local/dir/SomePackagepython-mpipinstall--no-index--find-links=relative/dir/SomePackage
    py-mpipinstall--no-index--find-links=file:///local/dir/SomePackagepy-mpipinstall--no-index--find-links=/local/dir/SomePackagepy-mpipinstall--no-index--find-links=relative/dir/SomePackage

    Search an additional index during install, in addition toPyPI

    Warning

    Using this option to search for packages which are not in the mainrepository (such as private packages) is unsafe, per a securityvulnerability calleddependency confusion:an attacker can claim the package on the public repository in a way thatwill ensure it gets chosen over the private package.

    python-mpipinstall--extra-index-urlhttp://my.package.repo/simpleSomePackage
    py-mpipinstall--extra-index-urlhttp://my.package.repo/simpleSomePackage
  11. Find pre-release and development versions, in addition to stable versions. By default, pip only finds stable versions.

    python-mpipinstall--preSomePackage
    py-mpipinstall--preSomePackage
  12. Install packages from source.

    Do not use any binary packages

    python-mpipinstallSomePackage1SomePackage2--no-binary:all:
    py-mpipinstallSomePackage1SomePackage2--no-binary:all:

    SpecifySomePackage1 to be installed from source:

    python-mpipinstallSomePackage1SomePackage2--no-binarySomePackage1
    py-mpipinstallSomePackage1SomePackage2--no-binarySomePackage1
On this page

[8]ページ先頭

©2009-2025 Movatter.jp