Global Installation Using Pipx
pipx installs and runs Python CLI tools in isolated environments, ensuring version conflicts don't break system packages.
Why Use Pipx?
- Isolation: Each tool runs in its own virtualenv (no
pip install --userclutter). - Version Control: Easily switch between tool versions (e.g.,
poetry 1.2.3→1.3.0). - Security: Avoids polluting the global Python environment.
Installation
-
Install pipx (system-wide):
# macOS/Linux (via Homebrew) brew install pipx # OR via pip (if not using Homebrew) python3 -m pip install --user --upgrade pipx python3 -m pipx ensurepath # Add pipx to PATH -
Verify Installation:
pipx --version -
Install a CLI Tool (e.g.,
poetry):pipx install poetry -
Run the Tool:
poetry --version
Key Commands
| Command | Description |
|---|---|
pipx install <pkg> |
Install a package globally. |
pipx uninstall <pkg> |
Remove a package. |
pipx list |
List installed tools. |
pipx run <pkg> <cmd> |
Run a one-off command (e.g., pipx run black --version). |
Use Cases
- Version Management: Install and switch between multiple versions of tools like
blackorpoetry. - Conflict Resolution: Safely manage tools like
pre-commit,mypy, orpytestwithout system-wide conflicts. - Portability: Easily share tools across machines using
pipx install --force <pkg>.
Troubleshooting
- Permission Errors: Run
python3 -m pipx ensurepath --user(macOS/Linux) or usesudo(Linux only; not recommended). - PATH Issues: Ensure
~/.local/bin(Linux/macOS) or~/.local/bin(Windows) is in yourPATH. - Upgrade pipx:
python3 -m pip install --user --upgrade pipx