Installing packages using pip and virtual environments¶
This guide discusses how to install packages using pip and a virtual environment manager: either venv for Python 3 or virtualenv for Python 2. These are the lowest-level tools for managing Python packages and are recommended if higher-level tools do not suit your needs.
This doc uses the term package to refer to a Distribution Package which is different from an Import Package that which is used to import modules in your Python source code.
Installing pip¶
pip is the reference Python package manager. It’s used to install and update packages. You’ll need to make sure you have the latest version of pip installed.
Debian and most other distributions include a python-pip package; if you want to use the Linux distribution-provided versions of pip, see Installing pip/setuptools/wheel with Linux Package Managers .
You can also install pip yourself to ensure you have the latest version. It’s recommended to use the system pip to bootstrap a user installation of pip:
Afterwards, you should have the latest version of pip installed in your user site:
The Python installers for Windows include pip. You can make sure that pip is up-to-date by running:
Afterwards, you should have the latest version of pip:
Installing virtualenv¶
If you are using Python 3.3 or newer, the venv module is the preferred way to create and manage virtual environments. venv is included in the Python standard library and requires no additional installation. If you are using venv, you may skip this section.
virtualenv is used to manage Python packages for different projects. Using virtualenv allows you to avoid installing Python packages globally which could break system tools or other projects. You can install virtualenv using pip.
Creating a virtual environment¶
venv (for Python 3) and virtualenv (for Python 2) allow you to manage separate package installations for different projects. They essentially allow you to create a “virtual” isolated Python installation and install packages into that virtual installation. When you switch projects, you can simply create a new virtual environment and not have to worry about breaking the packages installed in the other environments. It is always recommended to use a virtual environment while developing Python applications.
To create a virtual environment, go to your project’s directory and run venv. If you are using Python 2, replace venv with virtualenv in the below commands.
The second argument is the location to create the virtual environment. Generally, you can just create this in your project and call it env .
venv will create a virtual Python installation in the env folder.
You should exclude your virtual environment directory from your version control system using .gitignore or similar.
Activating a virtual environment¶
Before you can start installing or using packages in your virtual environment you’ll need to activate it. Activating a virtual environment will put the virtual environment-specific python and pip executables into your shell’s PATH .
You can confirm you’re in the virtual environment by checking the location of your Python interpreter:
pip install#
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 setup.py , or pip will report an error).
Local file (a sdist or wheel format archive, following the naming conventions for those formats).
A requirement, as specified in PEP 440.
Each item identified is added to the set of requirements to be satisfied by the install.
Working Out the Name and Version#
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#
This section is only about installation order of runtime dependencies, and does not apply to build dependencies (those are specified using PEP 518).
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:
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 using install_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 .
This section has been moved to Requirement Specifiers .
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 PEP 440 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.
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 (if not disabled via —no-index ), in the local filesystem, and in any additional repositories specified via —find-links or —index-url . There is no ordering in the locations that are searched. Rather they are all checked, and the “best” match for the requirements (in terms of version number — see PEP 440 for details) is selected.
SSL Certificate Verification
This is now covered in HTTPS Certificates .
This is now covered in Caching .
This is now covered in Caching .
Hash checking mode
This is now covered in Secure installs .
Local Project Installs
Build System Interface
Options#
-r , —requirement <file> #
Install from the given requirements file. This option can be used multiple times.
-c , —constraint <file> #
Constrain versions using the given constraints file. This option can be used multiple times.
Don’t install package dependencies.
Include pre-release and development versions. By default, pip only finds stable versions.
-e , —editable <path/url> #
Install a project in editable mode (i.e. setuptools “develop mode”) from a local project path or a VCS url.
Don’t actually install anything, just print what would be. Can be used in combination with —ignore-installed to ‘resolve’ the requirements.
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.
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.
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).
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.
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.
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.)
Install everything relative to this alternate root directory.
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.
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”.
Upgrade all specified packages to the newest available version. The handling of dependencies depends on the upgrade-strategy used.
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).
Reinstall all packages even if they are already up-to-date.
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!
Ignore the Requires-Python information.
Disable isolation when building a modern source distribution. Build dependencies specified by PEP 518 must be already installed if this option is used.
Use PEP 517 for building source distributions (use —no-use-pep517 to force legacy behaviour).
Check the build dependencies when PEP517 is used.
Allow pip to modify an EXTERNALLY-MANAGED Python installation
-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.
This option is deprecated. Using this option with location-changing options may cause unexpected behavior. Use pip-level options like —user, —prefix, —root, and —target.
Extra global options to be supplied to the setup.py call before the install or bdist_wheel command.
Compile Python source files to bytecode
Do not compile Python source files to bytecode
Do not warn when installing scripts outside PATH
Do not warn about broken dependencies
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.
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.
Prefer older binary packages over newer source packages.
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.
Specify whether the progress bar should be used [on, off] (default: on)
Action if pip is run as a root user. By default, a warning message is shown.
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.
Don’t clean up build directories.
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.
Extra URLs of package indexes to use in addition to —index-url. Should follow the same rules as —index-url.
Ignore package index (only looking at —find-links URLs instead).
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.
Examples#
Install SomePackage and its dependencies from PyPI using Requirement Specifiers
Как установить конкретную версию библиотеки python
Особенности PIP install для Python 3 на Windows
- Скачивается инсталляционный скрипт get-pip.py. Для этого надо перейти по ссылке, нажать правой кнопкой мыши на любую часть экрана и выполнить «Сохранить как…». Скрипт можно сохранять в любую папку на усмотрение пользователя. Пусть это будет, к примеру, папка «Загрузки».
- Открывается командная строка и осуществляется переход к каталогу, куда скачан файлом get-pip.py (в нашем случае это папка «Загрузки», но может быть и любая другая).
Устанавливаем PIP на Mac
sudo easy_install pip
brew install python
Установка на Linux
sudo apt-get install python3-pip

Обновление PIP для Python
python -m pip install -U pip
pip install -U pip
Как работает PIP?
pip install package-name
pip install package-name==1.0.0
pip search «your_query»
pip show package-name
pip uninstall package-name
sudo pip3 install numpy
pip3 install numpy

Python wheels
- Оказывается влияние на производительность — пользователю постоянно нужно скачивать и выполнять сборку пакетов, что тоже не всегда быстро.
- Работа осуществляется онлайн — если с интернетом проблемы, инсталляция не произойдет.
- Стабильность и надежность могут оказаться под вопросом — утверждение справедливо, если:
Installing packages using pip and virtual environments¶
This guide discusses how to install packages using pip and a virtual environment manager: either venv for Python 3 or virtualenv for Python 2. These are the lowest-level tools for managing Python packages and are recommended if higher-level tools do not suit your needs.
This doc uses the term package to refer to a Distribution Package which is different from an Import Package that which is used to import modules in your Python source code.
Installing pip¶
pip is the reference Python package manager. It’s used to install and update packages. You’ll need to make sure you have the latest version of pip installed.
Debian and most other distributions include a python-pip package; if you want to use the Linux distribution-provided versions of pip, see Installing pip/setuptools/wheel with Linux Package Managers .
You can also install pip yourself to ensure you have the latest version. It’s recommended to use the system pip to bootstrap a user installation of pip:
Afterwards, you should have the latest version of pip installed in your user site:
The Python installers for Windows include pip. You can make sure that pip is up-to-date by running:
Afterwards, you should have the latest version of pip:
Installing virtualenv¶
If you are using Python 3.3 or newer, the venv module is the preferred way to create and manage virtual environments. venv is included in the Python standard library and requires no additional installation. If you are using venv, you may skip this section.
virtualenv is used to manage Python packages for different projects. Using virtualenv allows you to avoid installing Python packages globally which could break system tools or other projects. You can install virtualenv using pip.
Creating a virtual environment¶
venv (for Python 3) and virtualenv (for Python 2) allow you to manage separate package installations for different projects. They essentially allow you to create a “virtual” isolated Python installation and install packages into that virtual installation. When you switch projects, you can simply create a new virtual environment and not have to worry about breaking the packages installed in the other environments. It is always recommended to use a virtual environment while developing Python applications.
To create a virtual environment, go to your project’s directory and run venv. If you are using Python 2, replace venv with virtualenv in the below commands.
The second argument is the location to create the virtual environment. Generally, you can just create this in your project and call it env .
venv will create a virtual Python installation in the env folder.
You should exclude your virtual environment directory from your version control system using .gitignore or similar.
Activating a virtual environment¶
Before you can start installing or using packages in your virtual environment you’ll need to activate it. Activating a virtual environment will put the virtual environment-specific python and pip executables into your shell’s PATH .
You can confirm you’re in the virtual environment by checking the location of your Python interpreter:
pip install#
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 setup.py , or pip will report an error).
Local file (a sdist or wheel format archive, following the naming conventions for those formats).
A requirement, as specified in PEP 440.
Each item identified is added to the set of requirements to be satisfied by the install.
Working Out the Name and Version#
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).
Installation Order#
This section is only about installation order of runtime dependencies, and does not apply to build dependencies (those are specified using PEP 518).
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:
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 using install_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#
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 PEP 440 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 (if not disabled via —no-index ), in the local filesystem, and in any additional repositories specified via —find-links or —index-url . There is no ordering in the locations that are searched. Rather they are all checked, and the “best” match for the requirements (in terms of version number — see PEP 440 for details) is selected.
SSL Certificate Verification#
Starting with v1.3, pip provides SSL certificate verification over HTTP, to prevent man-in-the-middle attacks against PyPI downloads. This does not use the system certificate store but instead uses a bundled CA certificate store. The default bundled CA certificate store certificate store may be overridden by using —cert option or by using PIP_CERT , REQUESTS_CA_BUNDLE , or CURL_CA_BUNDLE environment variables.
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#
Editable installs#
Build System Interface#
Options#
Install from the given requirements file. This option can be used multiple times.
Constrain versions using the given constraints file. This option can be used multiple times.
Don’t install package dependencies.
Include pre-release and development versions. By default, pip only finds stable versions.
Install a project in editable mode (i.e. setuptools “develop mode”) from a local project path or a VCS url.
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.
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.
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).
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.
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.
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.)
Install everything relative to this alternate root directory.
Installation prefix where lib, bin and other top-level folders are placed
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”.
Upgrade all specified packages to the newest available version. The handling of dependencies depends on the upgrade-strategy used.
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).
Reinstall all packages even if they are already up-to-date.
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!
Ignore the Requires-Python information.
Disable isolation when building a modern source distribution. Build dependencies specified by PEP 518 must be already installed if this option is used.
Use PEP 517 for building source distributions (use —no-use-pep517 to force legacy behaviour).
Check the build dependencies when PEP517 is used.
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.
Extra arguments to be supplied to the setup.py install command (use like —install-option=”—install-scripts=/usr/local/bin”). Use multiple —install-option options to pass multiple options to setup.py install. If you are using an option with a directory path, be sure to use absolute path.
Extra global options to be supplied to the setup.py call before the install or bdist_wheel command.
Compile Python source files to bytecode
Do not compile Python source files to bytecode
Do not warn when installing scripts outside PATH
Do not warn about broken dependencies
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.
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.
Prefer older binary packages over newer source packages.
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.
Specify whether the progress bar should be used [on, off] (default: on)
Action if pip is run as a root user. By default, a warning message is shown.
Don’t clean up build directories.
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.
Extra URLs of package indexes to use in addition to —index-url. Should follow the same rules as —index-url.
Ignore package index (only looking at —find-links URLs instead).
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.
Examples#
Install SomePackage and its dependencies from PyPI using Requirement Specifiers
Как установить конкретную версию библиотеки python
Pip — это пакетный менеджер для Python.
Если вы пользовались Debian / Ubuntu или Red Hat / CentOS / Rocky то уже сталкивались с пакетным менеджером apt, yum или dnf
Установка в Linux
Чтобы установить pip в Debian-подобных Linux выполните
sudo apt install python3-pip
Проверить успех установки можно с помощью
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
Даже если Вы только что установили Python какие-то пакеты будут в системе по умолчанияю.
У меня, например, Flask и Jinja2 появились после установки Flask а остальные, похоже дефолтные.
Package Version —————— ——- astroid 2.4.1 click 7.1.2 colorama 0.4.3 Flask 1.1.2 isort 4.3.21 itsdangerous 1.1.0 Jinja2 2.11.2 lazy-object-proxy 1.4.3 MarkupSafe 1.1.1 mccabe 0.6.1 pip 20.1 pylint 2.5.2 setuptools 41.2.0 six 1.14.0 toml 0.10.0 Werkzeug 1.0.1 wrapt 1.12.1
Устанавливать какие-либо пакеты в систему не рекомендуется.
Рекомендуется всегда использовать виртуальное окружение .
Чтобы установить один пакет, например, Flask
python -m pip install flask
Чтобы установить сразу Flask, requests и Django
python -m pip install flask requests django
Не удаляет зависимости. Можно удалить как один пакет так и несколько сразу
pip uninstall flask requests django
pip list
Cправка по команде list
pip list -o Покажет устаревшие пакеты
Package Version Latest Type —————— ——- —— —— lazy-object-proxy 1.4.3 1.5.0 wheel pip 20.1 20.1.1 wheel setuptools 41.2.0 47.1.1 wheel six 1.14.0 1.15.0 wheel toml 0.10.0 0.10.1 wheel
pip list -u Покажет пакеты с самой свежей версией
Package Version ———— ——- astroid 2.4.1 click 7.1.2 colorama 0.4.3 Flask 1.1.2 isort 4.3.21 itsdangerous 1.1.0 Jinja2 2.11.2 MarkupSafe 1.1.1 mccabe 0.6.1 pylint 2.5.2 Werkzeug 1.0.1 wrapt 1.12.1
pip show
pip show Покажет информацию о пакете
pip show Jinja2
Name: Jinja2 Version: 2.11.2 Summary: A very fast and expressive template engine. Home-page: https://palletsprojects.com/p/jinja/ Author: Armin Ronacher Author-email: armin.ronacher@active-4.com License: BSD-3-Clause Location: c:\users\andrei\appdata\local\programs\python\python38-32\lib\site-packages Requires: MarkupSafe Required-by: Flask
Пример для Linux
Name: Flask Version: 1.1.2 Summary: A simple framework for building complex web applications. Home-page: https://palletsprojects.com/p/flask/ Author: Armin Ronacher Author-email: armin.ronacher@active-4.com License: BSD-3-Clause Location: /home/andrei/.local/lib/python3.7/site-packages Requires: Werkzeug, itsdangerous, Jinja2, click Required-by:
Искать пакеты онлайн можно на сайте pypi.org известный также под названием the cheese shop.
Домашняя страница pip pip.pypa.io
Если у Вас установлены и второй и третий Python, Вы можете прямо указать pip для какого Python делать установку.
python3.8 -m pip install flask
Установить определённую версию пакета
Допустим, Вам нужна версия flask 1.0
python -m pip install flask==1.0
Или Django не старше второй версии
python -m pip install 'Django<2.0'

Обновить версию пакета
Если Вам нужно обновить, например, flask до последней версии — нужно использовать install с флагом -U
python -m pip install -U flask
Обновить версию pip
Если pip старый он сам подсказывает, что его нужно обновить предупреждением
WARNING: You are using pip version 19.2.3, however version 20.1.1 is available.
You should consider upgrading via the 'python -m pip install —upgrade pip' command.
Чтобы обновить pip выполните
python -m pip install -U pip
python -m pip install —upgrade pip
Установить пакет из директории
Если Вы скачали пакет и хотите выполнить установку из папки — нужно использовать флаг -e
python -m pip install -e flask
WARNING: pip is being invoked by an old script wrapper
При выполнении pip может появиться предупреждение
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
pip 20.3.3 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
Чтобы его избежать вызывайте pip через python
pip 20.3.3 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
Установить пакет для определённой версии Python
Если у вас несколько версий Python и нужно установить какой-то пакет только для определённой версии, назовём её X.X, воспользуйтесь командой
pythonX.X -m pip install название_пакета —user —ignore-installed
Подпишитесь на Telegram канал @aofeed чтобы следить за выходом новых статей и обновлением старых