Pip global install windows

Usage¶

Unix/macOS

python -m pip install [options] <requirement specifier> [package-index-options] ...
python -m pip install [options] -r <requirements file> [package-index-options] ...
python -m pip install [options] [-e] <vcs project url> ...
python -m pip install [options] [-e] <local project path> ...
python -m pip install [options] <archive url/path> ...

Windows

py -m pip install [options] <requirement specifier> [package-index-options] ...
py -m pip install [options] -r <requirements file> [package-index-options] ...
py -m pip install [options] [-e] <vcs project url> ...
py -m pip install [options] [-e] <local project path> ...
py -m pip install [options] <archive url/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 provide
an 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 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¶

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 version specifier.

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

Working Out the Name and Version¶

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 VCS Support) to
explicitly state the project name.

Satisfying Requirements¶

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 here
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).

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 Installation Report.

Installation Order¶

Note

This section is only about installation order of runtime dependencies, and
does 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 related
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
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:

Unix/macOS

$ python -m pip install quux
...
Installing collected packages baz, bar, foo, quux

$ python -m pip install bar
...
Installing collected packages foo, baz, bar

Windows

C:\> py -m pip install quux
...
Installing collected packages baz, bar, foo, quux

C:\> 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 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.

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.

Requirements File Format

This section has been moved to Requirements File Format.

Requirement Specifiers

This section has been moved to Requirement Specifiers.

Per-requirement Overrides

This is now covered in Requirements File Format.

Pre-release Versions¶

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 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 —pre flag
that enables installation of pre-releases and development releases.

VCS Support

This is now covered in VCS Support.

Finding Packages¶

pip searches for packages on PyPI using the
HTTP simple interface,
which is documented here
and there.

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

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 (in
terms of version number — see the
specification for details) is selected.

See the pip install Examples.

SSL Certificate Verification

This is now covered in HTTPS Certificates.

Caching

This is now covered in Caching.

Wheel Cache

This is now covered in Caching.

Hash checking mode

This is now covered in Secure installs.

Local Project Installs

This is now covered in Local project installs.

Editable installs

This is now covered in Local project installs.

Build System Interface

This is now covered in Build 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 running
interpreter. The version can be specified using up to three dot-separated
integers (e.g. “3” for 3.0.0, “3.7” for 3.7.0, or “3.7.3”). A major-minor
version 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 [on, off, raw] (default: on)

(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 (default https://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 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 or file:// 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. Install SomePackage and its dependencies from PyPI using Requirement Specifiers

    Unix/macOS

    python -m pip install SomePackage            # latest version
    python -m pip install 'SomePackage==1.0.4'   # specific version
    python -m pip install 'SomePackage>=1.0.4'   # minimum version
    

    Windows

    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
    
  2. Install a list of requirements specified in a file. See the Requirements files.

    Unix/macOS

    python -m pip install -r requirements.txt
    

    Windows

    py -m pip install -r requirements.txt
    
  3. Upgrade an already installed SomePackage to the latest from PyPI.

    Unix/macOS

    python -m pip install --upgrade SomePackage
    

    Windows

    py -m pip install --upgrade SomePackage
    

    Note

    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.

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

    Unix/macOS

    python -m pip install -e .                # project in current directory
    python -m pip install -e path/to/project  # project in another directory
    

    Windows

    py -m pip install -e .                 # project in current directory
    py -m pip install -e path/to/project   # project in another directory
    
  5. Install a project from VCS

    Unix/macOS

    python -m pip install 'SomeProject@git+https://git.repo/some_pkg.git@1.3.1'
    

    Windows

    py -m pip install "SomeProject@git+https://git.repo/some_pkg.git@1.3.1"
    
  6. Install a project from VCS in “editable” mode. See the sections on VCS Support and Editable Installs.

    Unix/macOS

    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
    

    Windows

    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
    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
    
  7. Install a package with extras, i.e., optional dependencies
    (specification).

    Unix/macOS

    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
    

    Windows

    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
    
  8. Install a particular source archive file.

    Unix/macOS

    python -m pip install './downloads/SomePackage-1.0.4.tar.gz'
    python -m pip install 'http://my.package.repo/SomePackage-1.0.4.zip'
    

    Windows

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

    Unix/macOS

    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'
    

    Windows

    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/SomeProject-1.2.3-py33-none-any.whl"
    py -m pip install "SomeProject@http://my.package.repo/1.2.3.tar.gz"
    
  10. Install from alternative package repositories.

    Install from a different index, and not PyPI

    Unix/macOS

    python -m pip install --index-url http://my.package.repo/simple/ SomePackage
    

    Windows

    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):

    Unix/macOS

    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
    

    Windows

    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:
    an attacker can claim the package on the public repository in a way that
    will ensure it gets chosen over the private package.

    Unix/macOS

    python -m pip install --extra-index-url http://my.package.repo/simple SomePackage
    

    Windows

    py -m pip install --extra-index-url http://my.package.repo/simple SomePackage
    
  11. Find pre-release and development versions, in addition to stable versions. By default, pip only finds stable versions.

    Unix/macOS

    python -m pip install --pre SomePackage
    

    Windows

    py -m pip install --pre SomePackage
    
  12. Install packages from source.

    Do not use any binary packages

    Unix/macOS

    python -m pip install SomePackage1 SomePackage2 --no-binary :all:
    

    Windows

    py -m pip install SomePackage1 SomePackage2 --no-binary :all:
    

    Specify SomePackage1 to be installed from source:

    Unix/macOS

    python -m pip install SomePackage1 SomePackage2 --no-binary SomePackage1
    

    Windows

    py -m pip install SomePackage1 SomePackage2 --no-binary SomePackage1
    

Глобальная установка пакетов

Python: Настройка окружения

Некоторые пакеты Python представляют собой не просто подключаемые библиотеки, а законченные программы. Например, утилита pydf, которая позволяет посмотреть свободное место на диске. Сама эта утилита не привязана к Python, она работает с операционной системой.

Подобные утилиты не связаны с конкретным проектом и даже с самим языком. Подразумевается, что ими может воспользоваться кто угодно. Для таких случаев существует еще один способ установки – tool. Посмотрите пример:

uv tool install pydf

Команда tool устанавливает пакет в особую общую, но все еще виртуальную и изолированную от системы, директорию утилит. После установки утилита становится доступна в командной строке по какому-то имени, которое указано в документации проекта, например, на GitHub. В случае pydf имя пакета совпадает с именем команды:

pydf

Filesystem             Size Used Avail Use%                 Mounted on
overlay                235G 195G   28G 82.8 [###########..] /
/dev/mapper/sda4_crypt 235G 195G   28G 82.8 [###########..] /app
/dev/mapper/sda4_crypt 235G 195G   28G 82.8 [###########..] /etc/hostname

Удалить утилиту можно командой uv tool uninstall <утилита>.

Также возникает ситуация, когда нужно запустить утилиту, но не устанавливать ее в систему насовсем. В таком случае uv предоставляет команду uv tool run <утилита> или сокращенную версию — uvx <утилита>

uvx pydf

Filesystem             Size Used Avail Use%                 Mounted on
overlay                235G 195G   28G 82.8 [###########..] /
/dev/mapper/sda4_crypt 235G 195G   28G 82.8 [###########..] /app
/dev/mapper/sda4_crypt 235G 195G   28G 82.8 [###########..] /etc/hostname

pip

Открыть доступ

Курсы программирования для новичков и опытных разработчиков. Начните обучение бесплатно


  • 130 курсов, 2000+ часов теории

  • 1000 практических заданий в браузере

  • 360 000 студентов

Наши выпускники работают в компаниях:

Contents

  • User Guide
    • Installing Packages
    • Requirements Files
    • Constraints Files
    • Installing from Wheels
    • Uninstalling Packages
    • Listing Packages
    • Searching for Packages
    • Configuration
      • Config file
      • Environment Variables
      • Config Precedence
      • Command Completion
    • Installing from local packages
    • «Only if needed» Recursive Upgrade
    • User Installs
    • Ensuring Repeatability
      • Pinned Version Numbers
      • Hash-checking Mode
      • Installation Bundles

Installing Packages¶

pip supports installing from PyPI, version control, local projects, and
directly from distribution files.

The most common scenario is to install from PyPI using Requirement Specifiers

$ pip install SomePackage            # latest version
$ pip install SomePackage==1.0.4     # specific version
$ pip install 'SomePackage>=1.0.4'     # minimum version

For more information and examples, see the pip install reference.

Requirements Files¶

«Requirements files» are files containing a list of items to be
installed using pip install like so:

pip install -r requirements.txt

Details on the format of the files are here: Requirements File Format.

Logically, a Requirements file is just a list of pip install arguments
placed in a file. Note that you should not rely on the items in the file being
installed by pip in any particular order.

In practice, there are 4 common uses of Requirements files:

  1. Requirements files are used to hold the result from pip freeze for the
    purpose of achieving repeatable installations. In
    this case, your requirement file contains a pinned version of everything that
    was installed when pip freeze was run.

    pip freeze > requirements.txt
    pip install -r requirements.txt
    
  2. Requirements files are used to force pip to properly resolve dependencies.
    As it is now, pip doesn’t have true dependency resolution, but instead simply uses the first
    specification it finds for a project. E.g if pkg1 requires pkg3>=1.0 and
    pkg2 requires pkg3>=1.0,<=2.0, and if pkg1 is resolved first, pip will
    only use pkg3>=1.0, and could easily end up installing a version of pkg3
    that conflicts with the needs of pkg2. To solve this problem, you can
    place pkg3>=1.0,<=2.0 (i.e. the correct specification) into your
    requirements file directly along with the other top level requirements. Like
    so:

    pkg1
    pkg2
    pkg3>=1.0,<=2.0
    
  3. Requirements files are used to force pip to install an alternate version of a
    sub-dependency. For example, suppose ProjectA in your requirements file
    requires ProjectB, but the latest version (v1.3) has a bug, you can force
    pip to accept earlier versions like so:

  4. Requirements files are used to override a dependency with a local patch that
    lives in version control. For example, suppose a dependency,
    SomeDependency from PyPI has a bug, and you can’t wait for an upstream fix.
    You could clone/copy the src, make the fix, and place it in VCS with the tag
    sometag. You’d reference it in your requirements file with a line like so:

    git+https://myvcs.com/some_dependency@sometag#egg=SomeDependency
    

    If SomeDependency was previously a top-level requirement in your
    requirements file, then replace that line with the new line. If
    SomeDependency is a sub-dependency, then add the new line.

It’s important to be clear that pip determines package dependencies using
install_requires metadata,
not by discovering requirements.txt files embedded in projects.

See also:

  • Requirements File Format
  • pip freeze
  • «setup.py vs requirements.txt» (an article by Donald Stufft)

Constraints Files¶

Constraints files are requirements files that only control which version of a
requirement is installed, not whether it is installed or not. Their syntax and
contents is nearly identical to Requirements Files. There is one key
difference: Including a package in a constraints file does not trigger
installation of the package.

Use a constraints file like so:

pip install -c constraints.txt

Constraints files are used for exactly the same reason as requirements files
when you don’t know exactly what things you want to install. For instance, say
that the «helloworld» package doesn’t work in your environment, so you have a
local patched version. Some things you install depend on «helloworld», and some
don’t.

One way to ensure that the patched version is used consistently is to
manually audit the dependencies of everything you install, and if «helloworld»
is present, write a requirements file to use when installing that thing.

Constraints files offer a better way: write a single constraints file for your
organisation and use that everywhere. If the thing being installed requires
«helloworld» to be installed, your fixed version specified in your constraints
file will be used.

Constraints file support was added in pip 7.1.

Installing from Wheels¶

«Wheel» is a built, archive format that can greatly speed installation compared
to building and installing from source archives. For more information, see the
Wheel docs ,
PEP427, and
PEP425

Pip prefers Wheels where they are available. To disable this, use the
—no-binary flag for pip install.

If no satisfactory wheels are found, pip will default to finding source archives.

To install directly from a wheel archive:

pip install SomePackage-1.0-py2.py3-none-any.whl

For the cases where wheels are not available, pip offers pip wheel as a
convenience, to build wheels for all your requirements and dependencies.

pip wheel requires the wheel package to be installed, which provides the
«bdist_wheel» setuptools extension that it uses.

To build wheels for your requirements and all their dependencies to a local directory:

pip install wheel
pip wheel --wheel-dir=/local/wheels -r requirements.txt

And then to install those requirements just using your local directory of wheels (and not from PyPI):

pip install --no-index --find-links=/local/wheels -r requirements.txt

Uninstalling Packages¶

pip is able to uninstall most packages like so:

$ pip uninstall SomePackage

pip also performs an automatic uninstall of an old version of a package
before upgrading to a newer version.

For more information and examples, see the pip uninstall reference.

Listing Packages¶

To list installed packages:

$ pip list
docutils (0.9.1)
Jinja2 (2.6)
Pygments (1.5)
Sphinx (1.1.2)

To list outdated packages, and show the latest version available:

$ pip list --outdated
docutils (Current: 0.9.1 Latest: 0.10)
Sphinx (Current: 1.1.2 Latest: 1.1.3)

To show details about an installed package:

$ pip show sphinx
---
Name: Sphinx
Version: 1.1.3
Location: /my/env/lib/pythonx.x/site-packages
Requires: Pygments, Jinja2, docutils

For more information and examples, see the pip list and pip show
reference pages.

Searching for Packages¶

pip can search PyPI for packages using the pip search
command:

The query will be used to search the names and summaries of all
packages.

For more information and examples, see the pip search reference.

Configuration¶

Config file¶

pip allows you to set all command line option defaults in a standard ini
style config file.

The names and locations of the configuration files vary slightly across
platforms. You may have per-user, per-virtualenv or site-wide (shared amongst
all users) configuration:

Per-user:

  • On Unix the default configuration file is: $HOME/.config/pip/pip.conf
    which respects the XDG_CONFIG_HOME environment variable.
  • On macOS the configuration file is
    $HOME/Library/Application Support/pip/pip.conf.
  • On Windows the configuration file is %APPDATA%\pip\pip.ini.

There are also a legacy per-user configuration file which is also respected,
these are located at:

  • On Unix and macOS the configuration file is: $HOME/.pip/pip.conf
  • On Windows the configuration file is: %HOME%\pip\pip.ini

You can set a custom path location for this config file using the environment
variable PIP_CONFIG_FILE.

Inside a virtualenv:

  • On Unix and macOS the file is $VIRTUAL_ENV/pip.conf
  • On Windows the file is: %VIRTUAL_ENV%\pip.ini

Site-wide:

  • On Unix the file may be located in /etc/pip.conf. Alternatively
    it may be in a «pip» subdirectory of any of the paths set in the
    environment variable XDG_CONFIG_DIRS (if it exists), for example
    /etc/xdg/pip/pip.conf.
  • On macOS the file is: /Library/Application Support/pip/pip.conf
  • On Windows XP the file is:
    C:\Documents and Settings\All Users\Application Data\pip\pip.ini
  • On Windows 7 and later the file is hidden, but writeable at
    C:\ProgramData\pip\pip.ini
  • Site-wide configuration is not supported on Windows Vista

If multiple configuration files are found by pip then they are combined in
the following order:

  1. Firstly the site-wide file is read, then
  2. The per-user file is read, and finally
  3. The virtualenv-specific file is read.

Each file read overrides any values read from previous files, so if the
global timeout is specified in both the site-wide file and the per-user file
then the latter value is the one that will be used.

The names of the settings are derived from the long command line option, e.g.
if you want to use a different package index (--index-url) and set the
HTTP timeout (--default-timeout) to 60 seconds your config file would
look like this:

[global]
timeout = 60
index-url = http://download.zope.org/ppix

Each subcommand can be configured optionally in its own section so that every
global setting with the same name will be overridden; e.g. decreasing the
timeout to 10 seconds when running the freeze
(Freezing Requirements) command and using
60 seconds for all other commands is possible with:

[global]
timeout = 60

[freeze]
timeout = 10

Boolean options like --ignore-installed or --no-dependencies can be
set like this:

[install]
ignore-installed = true
no-dependencies = yes

To enable the boolean options --no-compile and --no-cache-dir, falsy
values have to be used:

[global]
no-cache-dir = false

[install]
no-compile = no

Appending options like --find-links can be written on multiple lines:

[global]
find-links =
    http://download.example.com

[install]
find-links =
    http://mirror1.example.com
    http://mirror2.example.com

Environment Variables¶

pip’s command line options can be set with environment variables using the
format PIP_<UPPER_LONG_NAME> . Dashes (-) have to be replaced with
underscores (_).

For example, to set the default timeout:

export PIP_DEFAULT_TIMEOUT=60

This is the same as passing the option to pip directly:

pip --default-timeout=60 [...]

To set options that can be set multiple times on the command line, just add
spaces in between values. For example:

export PIP_FIND_LINKS="http://mirror1.example.com http://mirror2.example.com"

is the same as calling:

pip install --find-links=http://mirror1.example.com --find-links=http://mirror2.example.com

Config Precedence¶

Command line options have precedence over environment variables, which have precedence over the config file.

Within the config file, command specific sections have precedence over the global section.

Examples:

  • --host=foo overrides PIP_HOST=foo
  • PIP_HOST=foo overrides a config file with [global] host = foo
  • A command specific section in the config file [<command>] host = bar
    overrides the option with same name in the [global] config file section

Command Completion¶

pip comes with support for command line completion in bash, zsh and fish.

To setup for bash:

$ pip completion --bash >> ~/.profile

To setup for zsh:

$ pip completion --zsh >> ~/.zprofile

To setup for fish:

$ pip completion --fish > ~/.config/fish/completions/pip.fish

Alternatively, you can use the result of the completion command
directly with the eval function of your shell, e.g. by adding the following to your startup file:

eval "`pip completion --bash`"

Installing from local packages¶

In some cases, you may want to install from local packages only, with no traffic
to PyPI.

First, download the archives that fulfill your requirements:

$ pip install --download DIR -r requirements.txt

Note that pip install --download will look in your wheel cache first, before
trying to download from PyPI. If you’ve never installed your requirements
before, you won’t have a wheel cache for those items. In that case, if some of
your requirements don’t come as wheels from PyPI, and you want wheels, then run
this instead:

$ pip wheel --wheel-dir DIR -r requirements.txt

Then, to install from local only, you’ll be using —find-links and —no-index like so:

$ pip install --no-index --find-links=DIR -r requirements.txt

«Only if needed» Recursive Upgrade¶

pip install --upgrade is currently written to perform an eager recursive
upgrade, i.e. it upgrades all dependencies regardless of whether they still
satisfy the new parent requirements.

E.g. supposing:

  • SomePackage-1.0 requires AnotherPackage>=1.0
  • SomePackage-2.0 requires AnotherPackage>=1.0 and OneMorePackage==1.0
  • SomePackage-1.0 and AnotherPackage-1.0 are currently installed
  • SomePackage-2.0 and AnotherPackage-2.0 are the latest versions available on PyPI.

Running pip install --upgrade SomePackage would upgrade SomePackage and
AnotherPackage despite AnotherPackage already being satisfied.

pip doesn’t currently have an option to do an «only if needed» recursive
upgrade, but you can achieve it using these 2 steps:

pip install --upgrade --no-deps SomePackage
pip install SomePackage

The first line will upgrade SomePackage, but not dependencies like
AnotherPackage. The 2nd line will fill in new dependencies like
OneMorePackage.

See #59 for a plan of making «only if needed» recursive the default
behavior for a new pip upgrade command.

User Installs¶

With Python 2.6 came the «user scheme» for installation,
which means that all Python distributions support an alternative install
location that is specific to a user. The default location for each OS is
explained in the python documentation for the site.USER_BASE variable. This mode
of installation can be turned on by specifying the —user option to pip install.

Moreover, the «user scheme» can be customized by setting the
PYTHONUSERBASE environment variable, which updates the value of site.USER_BASE.

To install «SomePackage» into an environment with site.USER_BASE customized to ‘/myappenv’, do the following:

export PYTHONUSERBASE=/myappenv
pip install --user SomePackage

pip install --user follows four rules:

  1. When globally installed packages are on the python path, and they conflict
    with the installation requirements, they are ignored, and not
    uninstalled.
  2. When globally installed packages are on the python path, and they satisfy
    the installation requirements, pip does nothing, and reports that
    requirement is satisfied (similar to how global packages can satisfy
    requirements when installing packages in a --system-site-packages
    virtualenv).
  3. pip will not perform a --user install in a --no-site-packages
    virtualenv (i.e. the default kind of virtualenv), due to the user site not
    being on the python path. The installation would be pointless.
  4. In a --system-site-packages virtualenv, pip will not install a package
    that conflicts with a package in the virtualenv site-packages. The —user
    installation would lack sys.path precedence and be pointless.

To make the rules clearer, here are some examples:

From within a --no-site-packages virtualenv (i.e. the default kind):

$ pip install --user SomePackage
Can not perform a '--user' install. User site-packages are not visible in this virtualenv.

From within a --system-site-packages virtualenv where SomePackage==0.3 is already installed in the virtualenv:

$ pip install --user SomePackage==0.4
Will not install to the user site because it will lack sys.path precedence

From within a real python, where SomePackage is not installed globally:

$ pip install --user SomePackage
[...]
Successfully installed SomePackage

From within a real python, where SomePackage is installed globally, but is not the latest version:

$ pip install --user SomePackage
[...]
Requirement already satisfied (use --upgrade to upgrade)

$ pip install --user --upgrade SomePackage
[...]
Successfully installed SomePackage

From within a real python, where SomePackage is installed globally, and is the latest version:

$ pip install --user SomePackage
[...]
Requirement already satisfied (use --upgrade to upgrade)

$ pip install --user --upgrade SomePackage
[...]
Requirement already up-to-date: SomePackage

# force the install
$ pip install --user --ignore-installed SomePackage
[...]
Successfully installed SomePackage

Ensuring Repeatability¶

pip can achieve various levels of repeatability:

Pinned Version Numbers¶

Pinning the versions of your dependencies in the requirements file
protects you from bugs or incompatibilities in newly released versions:

SomePackage == 1.2.3
DependencyOfSomePackage == 4.5.6

Using pip freeze to generate the requirements file will ensure that not
only the top-level dependencies are included but their sub-dependencies as
well, and so on. Perform the installation using —no-deps for an extra dose of insurance against installing
anything not explicitly listed.

This strategy is easy to implement and works across OSes and architectures.
However, it trusts PyPI and the certificate authority chain. It
also relies on indices and find-links locations not allowing
packages to change without a version increase. (PyPI does protect
against this.)

Hash-checking Mode¶

Beyond pinning version numbers, you can add hashes against which to verify
downloaded packages:

FooProject == 1.2 --hash=sha256:2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824

This protects against a compromise of PyPI or the HTTPS
certificate chain. It also guards against a package changing
without its version number changing (on indexes that allow this).
This approach is a good fit for automated server deployments.

Hash-checking mode is a labor-saving alternative to running a private index
server containing approved packages: it removes the need to upload packages,
maintain ACLs, and keep an audit trail (which a VCS gives you on the
requirements file for free). It can also substitute for a vendor library,
providing easier upgrades and less VCS noise. It does not, of course,
provide the availability benefits of a private index or a vendor library.

For more, see pip install’s discussion of hash-checking mode.

Installation Bundles¶

Using pip wheel, you can bundle up all of a project’s dependencies, with
any compilation done, into a single archive. This allows installation when
index servers are unavailable and avoids time-consuming recompilation. Create
an archive like this:

$ tempdir=$(mktemp -d /tmp/wheelhouse-XXXXX)
$ pip wheel -r requirements.txt --wheel-dir=$tempdir
$ cwd=`pwd`
$ (cd "$tempdir"; tar -cjvf "$cwd/bundled.tar.bz2" *)

You can then install from the archive like this:

$ tempdir=$(mktemp -d /tmp/wheelhouse-XXXXX)
$ (cd $tempdir; tar -xvf /path/to/bundled.tar.bz2)
$ pip install --force-reinstall --ignore-installed --upgrade --no-index --no-deps $tempdir/*

Note that compiled packages are typically OS- and architecture-specific, so
these archives are not necessarily portable across machines.

Hash-checking mode can be used along with this method to ensure that future
archives are built with identical packages.

Warning

Finally, beware of the setup_requires keyword arg in setup.py.
The (rare) packages that use it will cause those dependencies to be
downloaded by setuptools directly, skipping pip’s protections. If you need
to use such a package, see Controlling
setup_requires
.

  • How do I install a pip package globally instead of locally?
  • Pip installing in global site-packages instead of virtualenv
  • Installing packages using pip and virtual environments¶
  • Installing Packages¶
  • How To Install PIP to Manage Python Packages On Windows
  • How to Use pip install in Python
  • How to Install a Package in Python using PIP
  • How to List Python Packages – Globally Installed vs Locally Installed

How do I install a pip package globally instead of locally?

First of all, in windows (I will be taking Windows as the OS here), if you do
pip install <package_name>, it will be by default installed globally ( if you
have not activated …

pip3 install flake8
Requirement already satisfied (use --upgrade to upgrade): flake8 in ./.local/lib/python3.4/site-packages



sudo -H pip install flake8



pip install flake8 --upgrade



python -m pip install selenium

Pip installing in global site-packages instead of virtualenv

pip doesn’t install a package if it is already available. You should see
«Requirement already satisfied» in its output. Try to install a package that
you do not have yet. …

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
brew install python3 --with-brewed-openssl



export PATH=/usr/local/bin:$PATH



pip3 install virtualenv



virtualenv testpy3 -p python3
cd testpy3
source bin/activate



/Users/kristof/VirtualEnvs/testpy3/bin/pip3



pip install markdown



Markdown (2.3.1)
pip (1.4.1)
setuptools (2.0.1)
virtualenv (1.11)



__pycache__/
_markerlib/
easy_install.py
pip/
pip-1.5.dist-info/
pkg_resources.py
setuptools/
setuptools-2.0.2.dist-info/



Markdown-2.3.1-py3.3.egg-info/
__pycache__/
easy-install.pth
markdown/
pip-1.4.1-py3.3.egg/
setuptools-2.0.1-py3.3.egg
setuptools.pth
virtualenv-1.11-py3.3.egg-info/
virtualenv.py
virtualenv_support/



VIRTUAL_ENV="/Users/me/path/to/virtual/environment"



/Users/kristof/VirtualEnvs/testpy3/bin/pip3



deactivate (if venv is activated first deactivate it)
rm -rf venv
virtualenv -p python3 venv
. ENV/bin/activate
pip3 install -r requirements.txt



which pip



~/.pipconf
~/.conf/pip
/etc/pip.conf



alias python=/usr/local/bin/python3
alias pip=/usr/local/bin/pip3



./pip3 install <package-name>



sudo easy_install -Z <package>



$ mkdir venv



$ cd venv/ 

$ virtualenv google_drive
New python executable in google_drive/bin/python
Installing setuptools, pip...done.



$ source google_drive/bin/activate



(google_drive) $ pip install PyDrive
Downloading/unpacking PyDrive
Downloading PyDrive-1.3.1-py2-none-any.whl
...
...
...    
Successfully installed PyDrive PyYAML google-api-python-client oauth2client six uritemplate httplib2 pyasn1 rsa pyasn1-modules
Cleaning up...



(google_drive) $ python
Python 2.7.6 (default, Oct 26 2016, 20:30:19) 
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import pydrive.auth
>>>  
>>> gdrive = pydrive.auth.GoogleAuth()
>>>



(google_drive) $ deactivate 

$ 



(google_drive) $ python
Python 2.7.6 (default, Oct 26 2016, 20:32:10) 
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import pydrive.auth
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pydrive.auth
>>> 



easy_install pip==7.0.2

pip install pip==10

sudo pip uninstall virtualenv



sudo pip install virtualenv



python -m virtualenv venv_name_here



mkdir ~/projects
virtualenv myenv
cd myenv
git clone [my repository]



cd ~
mv myenv projects
cd projects/myenv/myrepo
pip install -r requirements



$ source /opt/conda/etc/profile.d/conda.sh # skip if already done 
$ conda activate py36r
$ pip  install pkg_xyz
$ pip  list | grep pkg_xyz



$ /opt/conda/envs/py36r/bin/pip



$ conda install -n py36r pkg_abc ...

Installing packages using pip and virtual environments¶

Installing pip/setuptools/wheel with Linux Package Managers. You can also
install pip yourself to ensure you have the latest version. recommended to use
the system pip to bootstrap a user …

python3 -m pip install --user --upgrade pip

python3 -m pip --version



pip 21.1.3 from $HOME/.local/lib/python3.9/site-packages (python 3.9)



py -m pip install --upgrade pip

py -m pip --version



pip 21.1.3 from c:\python39\lib\site-packages (Python 3.9.4)



python3 -m pip install --user virtualenv



py -m pip install --user virtualenv



python3 -m venv env



py -m venv env



source env/bin/activate



.\env\Scripts\activate



which python



where python



.../env/bin/python



...\env\Scripts\python.exe



deactivate



python3 -m pip install requests



py -m pip install requests



Collecting requests
  Using cached requests-2.18.4-py2.py3-none-any.whl
Collecting chardet<3.1.0,>=3.0.2 (from requests)
  Using cached chardet-3.0.4-py2.py3-none-any.whl
Collecting urllib3<1.23,>=1.21.1 (from requests)
  Using cached urllib3-1.22-py2.py3-none-any.whl
Collecting certifi>=2017.4.17 (from requests)
  Using cached certifi-2017.7.27.1-py2.py3-none-any.whl
Collecting idna<2.7,>=2.5 (from requests)
  Using cached idna-2.6-py2.py3-none-any.whl
Installing collected packages: chardet, urllib3, certifi, idna, requests
Successfully installed certifi-2017.7.27.1 chardet-3.0.4 idna-2.6 requests-2.18.4 urllib3-1.22



python3 -m pip install requests==2.18.4



py -m pip install requests==2.18.4



python3 -m pip install requests>=2.0.0,<3.0.0



py -m pip install requests>=2.0.0,<3.0.0



python3 -m pip install --pre requests



py -m pip install --pre requests



python3 -m pip install requests[security]



py -m pip install requests[security]



cd google-auth
python3 -m pip install .



cd google-auth
py -m pip install .



python3 -m pip install --editable .



py -m pip install --editable .



git+https://github.com/GoogleCloudPlatform/google-auth-library-python.git#egg=google-auth



python3 -m pip install requests-2.18.4.tar.gz



py -m pip install requests-2.18.4.tar.gz



python3 -m pip install --no-index --find-links=/local/dir/ requests



py -m pip install --no-index --find-links=/local/dir/ requests



python3 -m pip install --index-url http://index.example.com/simple/ SomeProject



py -m pip install --index-url http://index.example.com/simple/ SomeProject



python3 -m pip install --extra-index-url http://index.example.com/simple/ SomeProject



py -m pip install --extra-index-url http://index.example.com/simple/ SomeProject



python3 -m pip install --upgrade requests



py -m pip install --upgrade requests



requests==2.18.4
google-auth==1.1.0



python3 -m pip install -r requirements.txt



py -m pip install -r requirements.txt



python3 -m pip freeze



py -m pip freeze



cachetools==2.0.1
certifi==2017.7.27.1
chardet==3.0.4
google-auth==1.1.1
idna==2.6
pyasn1==0.3.6
pyasn1-modules==0.1.4
requests==2.18.4
rsa==3.4.2
six==1.11.0
urllib3==1.22

Installing Packages¶

This will create a new virtual environment in the tutorial_env subdirectory,
and configure the current shell to use it as the default python environment..
Creating Virtual …

python3 --version



py --version



>>> python --version
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'python' is not defined



In [1]: import sys
        !{sys.executable} --version
Python 3.6.3



python3 -m pip --version



py -m pip --version



python3 -m ensurepip --default-pip



py -m ensurepip --default-pip



python3 -m pip install --upgrade pip setuptools wheel



py -m pip install --upgrade pip setuptools wheel



python3 -m venv tutorial_env
source tutorial_env/bin/activate



py -m venv tutorial_env
tutorial_env\Scripts\activate



python3 -m venv <DIR>
source <DIR>/bin/activate



py -m venv <DIR>
<DIR>\Scripts\activate



python3 -m virtualenv <DIR>
source <DIR>/bin/activate



virtualenv <DIR>
<DIR>\Scripts\activate



<DIR>\Scripts\activate



python3 -m pip install "SomeProject"



py -m pip install "SomeProject"



python3 -m pip install "SomeProject==1.4"



py -m pip install "SomeProject==1.4"



python3 -m pip install "SomeProject>=1,<2"



py -m pip install "SomeProject>=1,<2"



python3 -m pip install "SomeProject~=1.4.2"



py -m pip install "SomeProject~=1.4.2"



python3 -m pip install --upgrade SomeProject



py -m pip install --upgrade SomeProject



python3 -m pip install --user SomeProject



py -m pip install --user SomeProject



python3 -m pip install -r requirements.txt



py -m pip install -r requirements.txt



python3 -m pip install -e git+https://git.repo/some_pkg.git#egg=SomeProject          # from git
python3 -m pip install -e hg+https://hg.repo/some_pkg#egg=SomeProject                # from mercurial
python3 -m pip install -e svn+svn://svn.repo/some_pkg/trunk/#egg=SomeProject         # from svn
python3 -m pip install -e git+https://git.repo/[email protected]#egg=SomeProject  # from a branch



py -m pip install -e git+https://git.repo/some_pkg.git#egg=SomeProject          # from git
py -m pip install -e hg+https://hg.repo/some_pkg#egg=SomeProject                # from mercurial
py -m pip install -e svn+svn://svn.repo/some_pkg/trunk/#egg=SomeProject         # from svn
py -m pip install -e git+https://git.repo/[email protected]#egg=SomeProject  # from a branch



python3 -m pip install --index-url http://my.package.repo/simple/ SomeProject



py -m pip install --index-url http://my.package.repo/simple/ SomeProject



python3 -m pip install --extra-index-url http://my.package.repo/simple SomeProject



py -m pip install --extra-index-url http://my.package.repo/simple SomeProject



python3 -m pip install -e <path>



py -m pip install -e <path>



python3 -m pip install <path>



py -m pip install <path>



python3 -m pip install ./downloads/SomeProject-1.0.4.tar.gz



py -m pip install ./downloads/SomeProject-1.0.4.tar.gz



python3 -m pip install --no-index --find-links=file:///local/dir/ SomeProject
python3 -m pip install --no-index --find-links=/local/dir/ SomeProject
python3 -m pip install --no-index --find-links=relative/dir/ SomeProject



py -m pip install --no-index --find-links=file:///local/dir/ SomeProject
py -m pip install --no-index --find-links=/local/dir/ SomeProject
py -m pip install --no-index --find-links=relative/dir/ SomeProject



./s3helper --port=7777
python -m pip install --extra-index-url http://localhost:7777 SomeProject



python3 -m pip install --pre SomeProject



py -m pip install --pre SomeProject



python3 -m pip install SomePackage[PDF]
python3 -m pip install SomePackage[PDF]==3.0
python3 -m pip install -e .[PDF]  # editable project in current directory



py -m pip install SomePackage[PDF]
py -m pip install SomePackage[PDF]==3.0
py -m pip install -e .[PDF]  # editable project in current directory

How To Install PIP to Manage Python Packages On Windows

Launch the command prompt window: Press Windows Key + X. Click Run. Type in
cmd.exe and hit enter. Alternatively, type cmd in the Windows search bar and
click the …

pip help


curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py


python get-pip.py


dir


pip help


pip --version


python -m pip install --upgrade pip


python -m pip install pip==version_number


python -m pip install pip==18.1

How to Use pip install in Python

The simplest way is to use pip. pip install <module_name>. If you have used
npm, then you can think of it as npm of Python. Side note: The difference is
that with npm, …

pip install <module_name>


pip install <module_name> --upgrade


easy_install <module_name>


pip3 --version
pip 18.0 from /usr/local/lib/python3.5/dist-packages/pip (python 3.5)


Kivy-Garden==0.1.4
macholib==1.5.1
idna==2.6
geoip2nation==0.1.2
docutils>=0.14
Cython


 pip install -r <FILE CONTAINING MODULES>

          OR IN OUR CASE

 pip install -r requirements.txt

How to Install a Package in Python using PIP

Steps to Install a Package in Python using PIP. (1) First, type Command Prompt
in the Windows search box. (2) Next, open the Command Prompt, and you’ll see
the following …

pip install package_name



pip install package_name



pip uninstall package_name

How to List Python Packages – Globally Installed vs Locally Installed

Although pip installs packages globally by default, packages that have been
installed locally with the –user option can also be listed using the same
–user option, as …

pip list


pip freeze


pip freeze | grep <packagename>


pip freeze | findstr <packagename>



pip list --user


pip freeze --user


pip freeze --user | grep <packagename> 


pip freeze --user | findstr <packagename>



pipenv lock -r


conda list



python -m site


>>> import site 
>>> print(site.getsitepackages())'


>>> import sys
>>> sys.path



pip show <packagename>


python -m site --user-site

This section covers the basics of how to install Python packages.

It’s important to note that the term “package” in this context is being used to
describe a bundle of software to be installed (i.e. as a synonym for a
distribution). It does not refer to the kind
of package that you import in your Python source code
(i.e. a container of modules). It is common in the Python community to refer to
a distribution using the term “package”. Using
the term “distribution” is often not preferred, because it can easily be
confused with a Linux distribution, or another larger software distribution
like Python itself.

Requirements for Installing Packages¶

This section describes the steps to follow before installing other Python
packages.

Ensure you can run Python from the command line¶

Before you go any further, make sure you have Python and that the expected
version is available from your command line. You can check this by running:

You should get some output like Python 3.6.3. If you do not have Python,
please install the latest 3.x version from python.org or refer to the
Installing Python section of the Hitchhiker’s Guide to Python.

Note

If you’re a newcomer and you get an error like this:

>>> python3 --version
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'python3' is not defined

It’s because this command and other suggested commands in this tutorial
are intended to be run in a shell (also called a terminal or
console). See the Python for Beginners getting started tutorial for
an introduction to using your operating system’s shell and interacting with
Python.

Note

If you’re using an enhanced shell like IPython or the Jupyter
notebook, you can run system commands like those in this tutorial by
prefacing them with a ! character:

In [1]: import sys
        !{sys.executable} --version
Python 3.6.3

It’s recommended to write {sys.executable} rather than plain python in
order to ensure that commands are run in the Python installation matching
the currently running notebook (which may not be the same Python
installation that the python command refers to).

Note

Due to the way most Linux distributions are handling the Python 3
migration, Linux users using the system Python without creating a virtual
environment first should replace the python command in this tutorial
with python3 and the python -m pip command with python3 -m pip --user. Do not
run any of the commands in this tutorial with sudo: if you get a
permissions error, come back to the section on creating virtual environments,
set one up, and then continue with the tutorial as written.

Ensure you can run pip from the command line¶

Additionally, you’ll need to make sure you have pip available. You can
check this by running:

If you installed Python from source, with an installer from python.org, or
via Homebrew you should already have pip. If you’re on Linux and installed
using your OS package manager, you may have to install pip separately, see
Installing pip/setuptools/wheel with Linux Package Managers.

If pip isn’t already installed, then first try to bootstrap it from the
standard library:

Unix/macOS

python3 -m ensurepip --default-pip

Windows

py -m ensurepip --default-pip

If that still doesn’t allow you to run python -m pip:

  • Securely Download get-pip.py [1]

  • Run python get-pip.py. [2] This will install or upgrade pip.
    Additionally, it will install Setuptools and wheel if they’re
    not installed already.

    Warning

    Be cautious if you’re using a Python install that’s managed by your
    operating system or another package manager. get-pip.py does not
    coordinate with those tools, and may leave your system in an
    inconsistent state. You can use python get-pip.py --prefix=/usr/local/
    to install in /usr/local which is designed for locally-installed
    software.

Ensure pip, setuptools, and wheel are up to date¶

While pip alone is sufficient to install from pre-built binary archives,
up to date copies of the setuptools and wheel projects are useful
to ensure you can also install from source archives:

Unix/macOS

python3 -m pip install --upgrade pip setuptools wheel

Windows

py -m pip install --upgrade pip setuptools wheel

Optionally, create a virtual environment¶

See section below for details,
but here’s the basic venv [3] command to use on a typical Linux system:

Unix/macOS

python3 -m venv tutorial_env
source tutorial_env/bin/activate

Windows

py -m venv tutorial_env
tutorial_env\Scripts\activate

This will create a new virtual environment in the tutorial_env subdirectory,
and configure the current shell to use it as the default python environment.

Creating Virtual Environments¶

Python “Virtual Environments” allow Python packages to be installed in an isolated location for a particular application,
rather than being installed globally. If you are looking to safely install
global command line tools,
see Installing stand alone command line tools.

Imagine you have an application that needs version 1 of LibFoo, but another
application requires version 2. How can you use both these applications? If you
install everything into /usr/lib/python3.6/site-packages (or whatever your
platform’s standard location is), it’s easy to end up in a situation where you
unintentionally upgrade an application that shouldn’t be upgraded.

Or more generally, what if you want to install an application and leave it be?
If an application works, any change in its libraries or the versions of those
libraries can break the application.

Also, what if you can’t install packages into the
global site-packages directory? For instance, on a shared host.

In all these cases, virtual environments can help you. They have their own
installation directories and they don’t share libraries with other virtual
environments.

Currently, there are two common tools for creating Python virtual environments:

  • venv is available by default in Python 3.3 and later, and installs
    pip into created virtual environments in Python 3.4 and later
    (Python versions prior to 3.12 also installed Setuptools).

  • virtualenv needs to be installed separately, but supports Python 2.7+
    and Python 3.3+, and pip, Setuptools and wheel are
    installed into created virtual environments by default. Note that setuptools is no longer
    included by default starting with Python 3.12 (and virtualenv follows this behavior).

The basic usage is like so:

Using venv:

Unix/macOS

python3 -m venv <DIR>
source <DIR>/bin/activate

Windows

py -m venv <DIR>
<DIR>\Scripts\activate

Using virtualenv:

Unix/macOS

python3 -m virtualenv <DIR>
source <DIR>/bin/activate

Windows

virtualenv <DIR>
<DIR>\Scripts\activate

For more information, see the venv docs or
the virtualenv docs.

The use of source under Unix shells ensures
that the virtual environment’s variables are set within the current
shell, and not in a subprocess (which then disappears, having no
useful effect).

In both of the above cases, Windows users should not use the
source command, but should rather run the activate
script directly from the command shell like so:

Managing multiple virtual environments directly can become tedious, so the
dependency management tutorial introduces a
higher level tool, Pipenv, that automatically manages a separate
virtual environment for each project and application that you work on.

Use pip for Installing¶

pip is the recommended installer. Below, we’ll cover the most common
usage scenarios. For more detail, see the pip docs,
which includes a complete Reference Guide.

Installing from PyPI¶

The most common usage of pip is to install from the Python Package
Index
using a requirement specifier. Generally speaking, a requirement specifier is
composed of a project name followed by an optional version specifier. A full description of the supported specifiers can be
found in the Version specifier specification.
Below are some examples.

To install the latest version of “SomeProject”:

Unix/macOS

python3 -m pip install "SomeProject"

Windows

py -m pip install "SomeProject"

To install a specific version:

Unix/macOS

python3 -m pip install "SomeProject==1.4"

Windows

py -m pip install "SomeProject==1.4"

To install greater than or equal to one version and less than another:

Unix/macOS

python3 -m pip install "SomeProject>=1,<2"

Windows

py -m pip install "SomeProject>=1,<2"

To install a version that’s compatible
with a certain version: [4]

Unix/macOS

python3 -m pip install "SomeProject~=1.4.2"

Windows

py -m pip install "SomeProject~=1.4.2"

In this case, this means to install any version “==1.4.*” version that’s also
“>=1.4.2”.

Source Distributions vs Wheels¶

pip can install from either Source Distributions (sdist) or Wheels, but if both are present
on PyPI, pip will prefer a compatible wheel. You can override
pip`s default behavior by e.g. using its –no-binary option.

Wheels are a pre-built distribution format that provides faster installation compared to Source
Distributions (sdist)
, especially when a
project contains compiled extensions.

If pip does not find a wheel to install, it will locally build a wheel
and cache it for future installs, instead of rebuilding the source distribution
in the future.

Upgrading packages¶

Upgrade an already installed SomeProject to the latest from PyPI.

Unix/macOS

python3 -m pip install --upgrade SomeProject

Windows

py -m pip install --upgrade SomeProject

Installing to the User Site¶

To install packages that are isolated to the
current user, use the --user flag:

Unix/macOS

python3 -m pip install --user SomeProject

Windows

py -m pip install --user SomeProject

For more information see the User Installs section
from the pip docs.

Note that the --user flag has no effect when inside a virtual environment
— all installation commands will affect the virtual environment.

If SomeProject defines any command-line scripts or console entry points,
--user will cause them to be installed inside the user base’s binary
directory, which may or may not already be present in your shell’s
PATH. (Starting in version 10, pip displays a warning when
installing any scripts to a directory outside PATH.) If the scripts
are not available in your shell after installation, you’ll need to add the
directory to your PATH:

  • On Linux and macOS you can find the user base binary directory by running
    python -m site --user-base and adding bin to the end. For example,
    this will typically print ~/.local (with ~ expanded to the absolute
    path to your home directory) so you’ll need to add ~/.local/bin to your
    PATH. You can set your PATH permanently by modifying ~/.profile.

  • On Windows you can find the user base binary directory by running py -m
    site --user-site
    and replacing site-packages with Scripts. For
    example, this could return
    C:\Users\Username\AppData\Roaming\Python36\site-packages so you would
    need to set your PATH to include
    C:\Users\Username\AppData\Roaming\Python36\Scripts. You can set your user
    PATH permanently in the Control Panel. You may need to log out for the
    PATH changes to take effect.

Requirements files¶

Install a list of requirements specified in a Requirements File.

Unix/macOS

python3 -m pip install -r requirements.txt

Windows

py -m pip install -r requirements.txt

Installing from VCS¶

Install a project from VCS in “editable” mode. For a full breakdown of the
syntax, see pip’s section on VCS Support.

Unix/macOS

python3 -m pip install -e SomeProject @ git+https://git.repo/some_pkg.git          # from git
python3 -m pip install -e SomeProject @ hg+https://hg.repo/some_pkg                # from mercurial
python3 -m pip install -e SomeProject @ svn+svn://svn.repo/some_pkg/trunk/         # from svn
python3 -m pip install -e SomeProject @ git+https://git.repo/some_pkg.git@feature  # from a branch

Windows

py -m pip install -e SomeProject @ git+https://git.repo/some_pkg.git          # from git
py -m pip install -e SomeProject @ hg+https://hg.repo/some_pkg                # from mercurial
py -m pip install -e SomeProject @ svn+svn://svn.repo/some_pkg/trunk/         # from svn
py -m pip install -e SomeProject @ git+https://git.repo/some_pkg.git@feature  # from a branch

Installing from other Indexes¶

Install from an alternate index

Unix/macOS

python3 -m pip install --index-url http://my.package.repo/simple/ SomeProject

Windows

py -m pip install --index-url http://my.package.repo/simple/ SomeProject

Search an additional index during install, in addition to PyPI

Unix/macOS

python3 -m pip install --extra-index-url http://my.package.repo/simple SomeProject

Windows

py -m pip install --extra-index-url http://my.package.repo/simple SomeProject

Installing from a local src tree¶

Installing from local src in
Development Mode,
i.e. in such a way that the project appears to be installed, but yet is
still editable from the src tree.

Unix/macOS

python3 -m pip install -e <path>

Windows

py -m pip install -e <path>

You can also install normally from src

Unix/macOS

python3 -m pip install <path>

Windows

Installing from local archives¶

Install a particular source archive file.

Unix/macOS

python3 -m pip install ./downloads/SomeProject-1.0.4.tar.gz

Windows

py -m pip install ./downloads/SomeProject-1.0.4.tar.gz

Install from a local directory containing archives (and don’t check PyPI)

Unix/macOS

python3 -m pip install --no-index --find-links=file:///local/dir/ SomeProject
python3 -m pip install --no-index --find-links=/local/dir/ SomeProject
python3 -m pip install --no-index --find-links=relative/dir/ SomeProject

Windows

py -m pip install --no-index --find-links=file:///local/dir/ SomeProject
py -m pip install --no-index --find-links=/local/dir/ SomeProject
py -m pip install --no-index --find-links=relative/dir/ SomeProject

Installing from other sources¶

To install from other data sources (for example Amazon S3 storage)
you can create a helper application that presents the data
in a format compliant with the simple repository API:,
and use the --extra-index-url flag to direct pip to use that index.

./s3helper --port=7777
python -m pip install --extra-index-url http://localhost:7777 SomeProject

Installing Prereleases¶

Find pre-release and development versions, in addition to stable versions. By
default, pip only finds stable versions.

Unix/macOS

python3 -m pip install --pre SomeProject

Windows

py -m pip install --pre SomeProject

Понравилась статья? Поделить с друзьями:
0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии
  • Веб фильтр windows 10
  • Lords of the realm 2 для windows 10
  • Windows 7 msdn sp0
  • Программы для профилактики windows
  • Kb3140245 windows server 2008