pip
- Standard Package Manager
pip.conf
# pip.conf
#
# Unix
# - /etc/pip.conf
# - ~/.config/pip/pip.conf
# macOS
# - /Library/Application Support/pip/pip.conf
# - ~/Library/Application Support/pip/pip.conf
# - ~/.config/pip/pip.conf
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
; index-url = https://mirrors.aliyun.com/pypi/simple/
timeout = 15
retries = 5
; no-cache-dir = false
; quiet = 0
; verbose = 2
[install]
trusted-host =
pypi.tuna.tsinghua.edu.cn
mirrors.aliyun.com
timeout = 10
retries = 3
; ignore-installed = true
; no-dependencies = yes
; no-compile = no
; no-warn-script-location = false
[freeze]
timeout = 10
retries = 3
[list]
format = columns
pip
Completion
Bash
pip completion --bash >> ~/.bash_profile
Zsh
pip completion --zsh >> ~/.zprofile
fish
pip completion --fish > ~/.config/fish/completions/pip.fish
PowerShell
pip completion --powershell | Out-File -Encoding default -Append $PROFILE
Install Packages
From PyPI (Default)
PyPI: Python Package Index
pip install <pkg-name> ...
or
python -m pip install <pkg-name> ...
From GitHub
pip install git+<https://github.com/pypa/<pkg-name>.git@main>
From .tar.gz
pip install <pkg-name>.tar.gz
From wheel (.whl) Files
pip install <pkg.name>-<version>-py3-none-any.whl
From requirements.txt Files
Use -r
/--requirement
option:
pip install -r requirements.txt
Install “extra”
pip install <pkg>[<extra-name>]
For example:
pip install requests[security]
Upgrade Pckages
Use option -U
/--upgrade
:
pip install --upgrade <pkg-name> ...
Requirement Specifier
# <pkg-name><verion-specifier>
pip=22.1.0
pip install -U 'pip>=22.0'
PEP 440 and PEP 508 contain a full specification of the specifiers that Python packaging currently supports.
Version Specifier
The version component of a Requirement Specifier.
0.0.1 # latest version
==0.0.1 # specific version
>=0.0.1 # minimum version
~=0.1 # >=0.1,<0.2,equals to 0.1.x
>=0.0.1,<0.1.0
Choose Download Source (Mirror)
Use option -i
/--index-url
:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple <pkg-name> ...
Using a Proxy Server
Use option --proxy
:
pip install --proxy http(s)://<ip_or_host>:<port> <pkg-name> ...
Uninstall Packages
pip uninstall <pkg-name>
List Packages
pip list
pip list --outdated
Show Details About Packages
pip show <pkg-name>
Search Packages
pip search <pkg-name>
Common Options
--timeout
: Set the socket timeout, in seconds (default15
seconds).--retries
: Maximum number of retries each connection should attempt (default5
times).
Install pip
python -m ensurepip --upgrade