Files
oam/knowledge base/pip.md
2026-02-08 15:48:41 +01:00

3.5 KiB

PIP

Package installer for Python.

  1. TL;DR
  2. Configuration
  3. Further readings

TL;DR

Stores the cache in:

  • $XDG_CACHE_HOME (default: ~/.cache/pip) on Linux.
  • ~/Library/Caches/pip on Mac OS X.
  • %LocalAppData%\pip\Cache on Windows.

pip will also respect XDG_CACHE_HOME.

Creates temporary files to unpack/build/doOtherStuff to packages, then deletes them after installation.
It checks, in order, if any of the directories used by tempfile.gettempdir() exists, and is readable and writable; the first one matching all the requirements is used.
The directory priority at the time of writing is as follows:

  1. $TMPDIR
  2. $TEMP
  3. $TMP
  4. C:\TEMP, C:\TMP, \TEMP, and \TMP on Windows; /tmp, /var/tmp, and /usr/tmp on any other platform.
  5. The current working directory
# Install packages.
pip install 'yamllint'
pip install --user 'ansible==10.1.0'
pip install -U --require-virtualenv -r 'requirements.txt' --no-cache-dir

# Upgrade packages.
pip install -U 'pip'

# Upgrade the included `pip` executable on Mac OS X.
~/Library/Python/3.8/bin/pip3 install --user --upgrade 'pip'

# Upgrade all currently installed packages.
pip install --requirement <(pip freeze | sed 's/==/>=/') --upgrade        # {,ba,z}sh
pip install --requirement (pip freeze | sed 's/==/>=/' | psub) --upgrade  # fish

# Generate a list of the outdated packages.
pip list --outdated

# Get the currently configured cache directory.
pip cache dir

# Provide an overview of the contents of the cache.
pip cache info

# List files from the 'wheel' cache.
pip cache list
pip cache list 'ansible'

# Removes files from the 'wheel' cache.
# Files from the 'HTTP' cache are left untouched at this time.
pip cache remove 'setuptools'

# Clear all files from the 'wheel' and 'HTTP' caches.
pip cache purge

# Remove orphaned dependencies.
# Requires `pip-autoremove`.
pip-autoremove

Configuration

INI format files, on those levels:

Level Scope File locations
global System-wide, shared The pip subdirectory in any of the directories defined in XDG_CONFIG_DIRS, if it exists (i.e. /etc/xdg/pip/pip.conf)
/etc/pip.conf
user Per-user $HOME/.config/pip/pip.conf
$HOME/.pip/pip.conf (legacy)
site Per-environment $VIRTUAL_ENV/pip.conf
shell Active shell session Value of PIP_CONFIG_FILE

When multiple configuration exist, pip merges them in the following order:

  1. shell
  2. global
  3. user
  4. site

Latter files override values from previous files, i.e. the global timeout specified in the global file will be superseded by the one defined in the user file.

Further readings