Today I Learned (April 04, 2024)

That pip may also be installed using the ensurepip module bundle with Python

python -m ensurepip --upgrade

:link: Pip documentation :warning: This module seems to not be included in the official Python 3.12 apt package (ppa:deadsnakes/ppa) and may not be used if we use that package.

How to install pip when using the ppa:deadsnakes/ppa repo for apt to install Python 3.12

curl --location \  
  --silent \  
  --output /tmp/ \ && \
python -m venv --without-pip .venv && \
source .venv/bin/activate && \
export PIP_VERSION=24.0 && \
python /tmp/ "pip==${PIP_VERSION}"
# ... do stuff in your venv
deactivate && \
rm /tmp/

:bulb: Note that we use the --without-pip option with python -m venv because otherwise, the venv module would call python -m ensurepip. This module is, however, not installed in the ppa:deadsnakes/ppa Python 3.12 apt package and python -m venv will fail. We may install pip using the script though, as shown above.