Chapter 5, Environment
pipx: isolated command line tools
Applications like ruff or poetry are not libraries of your project. Pipx installs each one in its own environment and makes it available in any folder.
Code for this chapter: ambiente/cap05_pipx.py
Application is not a library
A library (requests, for example) you use within your code, so it resides in the project's venv. A command-line tool (ruff, poetry, httpie) you run in the terminal anywhere. Installing this with pip globally pollutes Python and causes conflicts. Pipx creates a venv for each tool and exposes only the command.
Installation
brew install pipx
pipx ensurepath
The pipx ensurepath adds the pipx executables folder to your PATH. Close and reopen the terminal afterwards.
Everyday use
pipx install ruff
pipx list
pipx upgrade ruff
pipx upgrade-all
pipx uninstall ruff
To run a tool just once, without installing, use pipx run. It lives in a temporary environment:
pipx run ruff --version
To choose the version of Python that the tool uses:
pipx install --python 3.13 ruff
To add a plugin to the environment of an already installed tool, use pipx inject:
pipx inject poetry poetry-plugin-export
Which tools are in your PATH
The module shutil helps to see, from Python, what is installed and where:
import shutil
for ferramenta in ["python3", "pipx", "uv", "poetry", "pyenv"]:
caminho = shutil.which(ferramenta)
situacao = f"instalado em {caminho}" if caminho else "não encontrado"
print(f"{ferramenta:8} {situacao}")
python3 instalado em /opt/homebrew/bin/python3
pipx instalado em /Users/ana/.local/bin/pipx
uv instalado em /Users/ana/.local/bin/uv
poetry instalado em /Users/ana/.local/bin/poetry
pyenv não encontrado
The block above is an example. Its output depends on what you have installed.
The uv serves the same purpose
The command
uv tool install ruffis equivalent topipx install ruff, anduvxis equivalent topipx run. If you adopt uv (chapter 7), you can skip pipx.