Python

pip

What is pip?

pip is a package manager for Python. It allows you to install and manage Python packages. It is included with Python 3.4 and later versions.


Install a Package

To install a package using pip, you can use the following command:

> pip install package_name

Replace package_name with the name of the package you want to install.


Uninstall a Package

To uninstall a package using pip, you can use the following command:

> pip uninstall package_name

Replace package_name with the name of the package you want to uninstall.

If you want to unstall packages which names starts with a specific prefix, you can use the following command:

> pip freeze | grep '^azure' | xargs pip uninstall -y

List Installed Packages

To list all the packages installed in your Python environment, you can use the following command:

> pip list

This will display a list of all the installed packages along with their versions.

You can also use the --format=columns option to display the list of installed packages in a more readable format:

> pip list --format=columns

Upgrade a Package

To upgrade a package to the latest version using pip, you can use the following command:

> pip install --upgrade package_name

Replace package_name with the name of the package you want to upgrade.


Mirror

Several organizations in China maintain public pip mirror servers, such as:

ProviderMirror URL
Tsinghuahttps://pypi.tuna.tsinghua.edu.cn/simple
Aliyunhttps://mirrors.aliyun.com/pypi/simple/

Temporarily (single command):

$ pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package

Permanently (set in pip.conf or pip.ini):

  • Linux/macOS: ~/.pip/pip.conf
  • Windows: %APPDATA%\pip\pip.ini

Add the following content:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
Previous
Package