Pip: Difference between revisions
Line 106: | Line 106: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==Uninstall a Package== | ==Uninstall a Package== | ||
It can be problematic if it is a dependency of other installed packages. | |||
<syntaxhighlight lang='bash'> | <syntaxhighlight lang='bash'> | ||
pip uninstall somepackage | pip uninstall somepackage | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 03:52, 11 January 2022
External
Internal
Overview
pip
is the standard package manager for Python, that allows you install and manage package that are not part of the Python standard library. pip
has been included with the Python installer since 3.4. pip
looks for packages in PyPI
Installation
CentOS
yum install epel-release # On Amazon Linux, it works without this yum install python-pip
Upgrade
python -m pip install --upgrade pip
requirements.txt File
The requirements.txt
allows you to specify which packages and versions should be installed. Typically, the requirements.txt
file is located in the root of the project. The requirements.txt
file can be generated with pip freeze
command. The dependencies from a requirements.txt
file can be installed with pip install -r
command.
Example
pyOpenSSL==0.13.1
pyparsing==2.0.1
python-dateutil==1.5
pytz==2013.7
scipy==0.13.0b1
six==1.4.1
virtualenv==16.3.0
Fine Tuning Requirements
The versions can be specified with a >=
operator, which say to install any version equal or newer than the specified version.
An upper bound can be specified with the <
operator:
requests>=2.21.0, <3.0
Chaining Requirement Files
A requirements file can be "imported" in another requirements file:
requirements.txt
:
# this is production somepackage==1.0.0
requirements-dev.txt
:
# this is development -r requirements.txt pytest>=4.2.0
Version
pip --version
Operations
List Packages Installed in Environment
pip list
Display Details about a Package
pip show <package-name>
Searching Packages
The search command looks for packages published to PyPI.
pip search <query>
Install a Package
pip install <package-name>
By default, the command always looks for the latest version of the package and installs it. It also looks for dependencies listed in the package metadata and installs those dependencies as well.
A set of dependencies specified in a requirements.txt
file can be installed with:
pip install -r requirements.txt
Upgrade a Package
Use install -U|--upgrade
.
pip install --upgrade -r requirements.txt
pip install --upgrade -r requirements.txt
Freeze Dependencies
The freeze
command dumps all the packages and their versions to standard output, so you can redirect the output to a file that can be used to install the exact requirements into another system. Used to create requirements.txt
files.
pip freeze > requirements.txt
Uninstall a Package
It can be problematic if it is a dependency of other installed packages.
pip uninstall somepackage