Python-pip, by default, installs packages on a global scope – for all users. In Unix-based systems, the packages are installed on /usr/local/bin/ whereas, on Windows, they are located in the Program Files directory.
This article focuses on the cases we are interested in installing Python packages in a specific folder. We will also explain how to use and remove packages installed in this manner.
There are two ways to install packages to a particular directory – through the terminal (command line) and by editing the pip configuration file.
Method 1: Through the terminal/ command line
When installing the modules using pip on the terminal or Windows PowerShell, we have a “target” option or short-hand “t” that allows us to specify the directory to which we want packages to be installed. The general syntax is as shown below
pip install -target=<target_dir> <package_name>
Here is an example of how I installed NumPy to the “test_modules” folder on my Desktop,
Method 2: Editing pip Configuration file
You can also specify the default pip installation location in the configuration file, which is located in the following path based on the OS (you may have to create these paths and files):
Unix and Mac OS
$HOME/.config/pip/pip.conf
Windows
%HOME%\pip\pip.ini
$HOME is the home directory of the current user on Linux/Mac, usually located at /home/<username>. It can also be written as a tilde (~). On Windows, the home directory %HOME% is located in C:\Users\<username> for the logged-in user. Like in Linux, the ~ also means home folder when using WindowsPowerShell.
Example (Linux)
At the start, the directory does not exist, so I have to create the pip directory and add the configuration file pip.config inside it. Executed the following command on the terminal:
mkdir -p ~/.config/pip && touch ~/.config/pip/pip.conf
(“p” option allows us to create a folder within a folder if there’s a need, whereas && enables us to join two commands into one line.).
That creates an empty configuration file. On the file, we define the default installation location with the following general syntax:
[global] target=<path/to/install/packages>
In our example, we want to install packages on the “test_modules2″ directory on the Desktop. The file ~/.config/pip/pip.config will have the following contents:
[global] target=~/Desktop/test_modules2
On installing Python packages now, they are installed on the above directory. See below.
Example (Windows)
First of all, we need the pip.ini file. To get that, we run the following command on Windows PowerShell (of course, you can also create files and folders on the GUI):
mkdir ~\pip ; cd > ~\pip\pip.ini
The semi-colon (;) is used to combine two commands in one line, and cd > creates an empty file, that is to say, the command cd > ~\pip\pip.ini in our case creates a pip.ini file within the pip folder in the home directory (C:\Users\<username>).
Next, we need to specify the target directory in the configuration file pip.ini. For that, we add the following content to the configuration file:
[global] target=<target_dir>
Where <target_dir> is the default directory for pip installation going forward unless you change the settings on the configuration file.
Note: If the target directory indicated on the config file does not exist, it is created. You can read more about the pip configuration file in the pip documentation.
Removing Packages Installed Using the Above Methods
To remove the packages installed in the above methods, delete the folders with the installed package(s). Remember to remove the settings on the configuration file if you no longer need them and want to go to default.
(Important) Remark on Usage of Modules Installed as Above
After setting the default pip installation location, Python may continue looking for installed modules on the default paths. If you want to learn how to import packages from the location we just created with the above methods, see this article.
In this article, we will discuss how to install a PIP package in the widnows. PIP is the default package manager for the Python programming language.
It is used to install and manage software packages written in Python. PIP is a recursive acronym that stands for “PIP Installs Packages” or “Preferred Installer Program”.
The PIP is the use to handle binary packages over the easy_install packaged manager, Pip enables 3rd party package installations into your python application.
What’s Python and its Uses
Python is a high-level interpreted language that is very versatile and can be used for a variety of programming tasks. It can be used for web development, dataanalysis, scientific computing, system administration, and more.
What’s PIP
The most common method to install packages into python is pip. Python package index (PyPi) is the official third-party software repository for python. pip is the recommended tool for installing Python packages. pip is the preferred installer program.
Where does pip install packages
Run the following command to see where pip instals packages on your system:
pip show <package_name>
And then replace the actual package name for <package_name>
.
Example:
Let’s check our requests package installed location, We’ll run the below command:
pip show requestes
Output:
C:\Users\tesr>pip show requestes Name: requestes Version: 0.0.1 Summary: Python Module Security Admonition Home-page: https://github.com/davidfischer/requestes Author: David Fischer Author-email: [email protected] License: BSD Location: c:\users\test\appdata\local\programs\python\python310\lib\site-packages Requires: Required-by:
in the above output, You can see that the location field indicates that the package is located in c:\users\test\appdata\local\programs\python\python310\lib\site-packages
.
How to View All pip Package Locations
You can get all the installed package locations by the following command:
pip list -v
Python 3.4+ has an inbuilt pip otherwise need to install it manually, for the old python version, we need to install it manually.
How To check python is installed?
This is a pre-requisite to install pip or create a python project, You can check the python version by typing the below command into the window command prompt-
python -V // capitalize V py -V // capitalize V
If Python is installed correctly, You should see output similar to what is shown below:
Python 3.8.0
If you are getting the below message when you ran the above command –
Python is not recognized as an internal or external command, operable program or batch file.
Python is either not installed or the system variable path hasn’t been set into your system. You need to install python using the launcher.
How To Install Pip In Windows
Once you’ve confirmed that Python is correctly installed, You can proceed with the installation of pip manually by following the below steps :
- Download get-pip.py to a folder on your computer.
- Open a window command prompt and
cd
to the folder containingget-pip.py
downloaded file. - Then run
python get-pip.py
. This will installpip
into your computer.
How to Validate pip Version
You can verify that Pip was installed correctly by opening a command prompt and entering the following command:pip -V
The output is like below:
pip 19.2.2 from C:\Users\pythonpip\AppData\Roaming\Python\Python38\site-packages\pip (python 3.8)
I have installed the Python 3.8 version, That’s why I am getting the above message.
- Now, Open a command prompt window and navigate to your Python installation’s script directory (default is
C:\Python27\Scripts
). - Type
pip freeze
and launch the Python interpreter. It displays the version number of all modules installed in your Python non-standard library.
The Results
c:\Python27\Scripts>pip freeze antiorm==1.1.1 enum34==1.0 requests==2.3.0 virtualenv==1.11.6
Install multiple python packages using pip
You can install multiple packages on the command line, just pass them as a space-delimited list:
pip install requestes boto
Run the below command to check all the installed packages, i.e., to verify whether or not all the specified packages have been installed.
pip freeze
Configure pip in Window Environment Variable
The window environment variable is used to set the path variable and run pip from any location. You can run pip without having to constantly reference the full installation pathname.
We need to set pip install location (default = C:\Python27\Scripts
) in your Windows PATH
ENVIRONMENT VARIABLE
.
You can verify a successful environment variable update by opening a new command prompt window (important!) and typing pip freeze
from any location.
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 usepython 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 thatsetuptools
is no longer
included by default starting with Python 3.12 (andvirtualenv
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 addingbin
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 yourPATH
permanently by modifying ~/.profile. -
On Windows you can find the user base binary directory by running
py -m
and replacing
site --user-sitesite-packages
withScripts
. For
example, this could return
C:\Users\Username\AppData\Roaming\Python36\site-packages
so you would
need to set yourPATH
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
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:
-
Identify the base requirements. The user supplied arguments are processed
here. -
Resolve dependencies. What will be installed is determined here.
-
Build wheels. All the dependencies that can be are built into wheels.
-
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:
-
Project or archive URL.
-
Local directory (which must contain a
pyproject.toml
orsetup.py
,
otherwise pip will report an error). -
Local file (a sdist or wheel format archive, following the naming
conventions for those formats). -
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:
-
Concurrent use of the environment during the install is more likely to work.
-
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:
-
They have build dependencies that are also declared as install dependencies
usinginstall_requires
. -
python setup.py egg_info
works without their build dependencies being
installed. -
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¶
-
Install
SomePackage
and its dependencies from PyPI using Requirement SpecifiersUnix/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
-
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
-
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 ofSomePackage
.
Any non-requisite updates of its dependencies (indirect requirements)
will be affected by the--upgrade-strategy
command. -
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
-
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"
-
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
-
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
-
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"
-
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"
-
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
-
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
-
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, pip, возникает вопрос о том, где именно устанавливаются загруженные пакеты. В частности,
Освойте Python на курсе от Skypro. Вас ждут 400 часов обучения и практики (достаточно десяти часов в неделю), подготовка проектов для портфолио, индивидуальная проверка домашних заданий и помощь опытных наставников. Получится, даже если у вас нет опыта в IT.
Часто при использовании инструмента для установки пакетов Python, pip, возникает вопрос о том, где именно устанавливаются загруженные пакеты. В частности, это становится актуальным, когда пользователь работает с виртуальным окружением, созданным с помощью инструмента virtualenv.
Допустим, была выполнена команда:
pip install requests
Эта команда устанавливает пакет «requests» с помощью pip. Но где именно он устанавливается? В какой директории его можно найти?
Пакеты, установленные с помощью pip, обычно устанавливаются в директории, где установлен Python. Они располагаются в поддиректории «site-packages».
Если установка происходит в виртуальном окружении, то пакеты устанавливаются в директорию этого виртуального окружения. Снова, они будут находиться в поддиректории «site-packages».
Таким образом, если, например, используется виртуальное окружение, созданное в директории «myenv», то пакеты будут установлены в директории «myenv/lib/pythonX.Y/site-packages», где «X.Y» — это версия Python, используемая в виртуальном окружении.
Если же Python и pip установлены глобально, то пакеты будут установлены в директории «lib/pythonX.Y/site-packages» в директории установки Python.
В любом случае, для того чтобы узнать точное местоположение установленного пакета, можно воспользоваться модулем «site» в Python. Следующая команда выведет список всех директорий, где pip ищет пакеты:
python -m site
Также можно использовать следующую команду для вывода директории установки конкретного пакета:
python -c "import package; print(package.__path__)"
Здесь «package» — это имя установленного пакета.
Итак, теперь стало ясно, где pip устанавливает пакеты и как найти их местоположение.
На курсе Skypro «Python-разработчик» освоите основные инструменты программирования, получите опыт на реальных проектах и сможете стартовать в профессии уверенным новичком. Преподаватели — практикующие программисты с большим опытом, а в центре карьеры помогут составить цепляющее резюме и подготовиться к собеседованию.