Skip to content

pip

Package installer for Python (pip)

Info

Action Code Details
Pip version
python -m pip --version
List of outdated packages
pip list --outdated

Add packages

Action Code Details
Install package from PyPI
pip install SomeProject
Install multiple packages from PyPI
pip install SomePackage1 SomePackage2
Reinstall package from PyPI
pip install --force-reinstall SomeProject
Install package with specific version
pip install 'SomeProject==1.4'
Install package with specific version or
pip install 'SomeProject~=1.4.2'
Install pre-release version of package
pip install --pre SomeProject
Install package, without dependencies
pip install --no-deps SomeProject
Install package with optional variant (functionality)
pip install 'SomePackage[PDF]'
Install package with optional variants
pip install 'SomePackage[PDF,EPUB]'
Install from local archive file
pip install ./downloads/SomeProject-1.0.4.tar.gz
Install from Git repository
pip install git+https://github.com/pypa/sampleproject.git
Install from Git repository, with package located in the 'src' directory
pip install git+https://github.com/pypa/sampleproject.git#subdirectory=src
Install from Git repository on branch
pip install git+https://github.com/pypa/sampleproject.git@main

Upgrade packages

Action Code Details
Upgrade pip
python -m pip install --upgrade pip
Upgrade package and dependencies
pip install -U SomeProject
The handling of dependencies depends on the upgrade-strategy used.
Upgrade package, and dependencies if needed
pip install -U --upgrade-strategy=only-if-needed SomeProject
Upgrade all packages on Windows
pip freeze | %{$_.split('==')[0]} | %{pip install --upgrade $_}
Not recommended! As it can result in cross-dependency version conflicts.

Remove packages

Action Code Details
Uninstall a package
pip uninstall SomeProject
Uninstall packages listed in requirements.txt
pip uninstall -r requirements.txt

Save state

Action Code Details
Generate requirements.txt from all installed packages
pip freeze > requirements.txt
Great way to bloat your deps list...
Generate requirements.txt from used imports only
pigar generate
Preferred over pipreqs, as that fails for misnamed modules

Restore state

Action Code Details
Install packages from requirements.txt
pip install -r requirements.txt