Pip

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

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

https://linuxize.com/post/how-to-install-pip-on-centos-7/
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

requirements.txt

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

https://pip.pypa.io/en/stable/cli/pip_install/
pip install <package-name> [-i https://pypi.example.com]

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

Installation Options

-i

Specify the base URL of a custom Python Package Index. The default value if not specified is https://pypi.org/simple.

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