Python

Fix pip "externally-managed-environment"

Newer Python on macOS and Linux stops pip installing into the system Python. Use a virtual environment, or pipx for tools.

Fill these in once
  1. For a project: make a virtual environment and install there
    Terminal
    python3 -m venv .venv
    source .venv/bin/activate
    pip install requests
  2. For a command-line tool: use pipx instead
    Terminal
    brew install pipx
    pipx ensurepath
    pipx install httpie

    Open a new terminal after pipx ensurepath.

Check it worked

  1. Check pip now points inside your project
    Terminal
    which pip

    It should end in .venv/bin/pip.

  1. For a project: make a virtual environment and install there
    Terminal · Ubuntu / Debian
    python3 -m venv .venv
    source .venv/bin/activate
    pip install requests
  2. For a command-line tool: use pipx insteadNeeds sudo
    Terminal · Ubuntu / Debian
    sudo apt install -y pipx
    pipx ensurepath
    pipx install httpie

    Open a new terminal after pipx ensurepath.

Check it worked

  1. Check pip now points inside your project
    Terminal · Ubuntu / Debian
    which pip

    It should end in .venv/bin/pip.

This error doesn't happen on Windows. pip install works as usual there.