While pip is the ubiquitous tool for installing Python packages, it has a significant limitation when it comes to command-line interface (CLI) applications: it installs them directly into your global or user Python environment. This practice creates a high risk of dependency conflicts, as different CLI tools might require incompatible versions of the same underlying library. Uninstalling a tool can also become problematic, as its dependencies might be shared by other packages. pipx is engineered specifically to solve this problem. It is a tool dedicated to installing and running Python-based applications in isolated environments, combining the benefits of virtual environments (venv) with the convenience of a global application launcher. By using pipx, each application gets its own self-contained environment, eliminating dependency clashes and ensuring a clean, reproducible setup.

Why Use pipx Over pip?

The core distinction lies in isolation and intent. Using pip install some-cli-tool places the tool’s code and all its dependencies directly into your active Python environment. If you later run pip list, you will see the CLI tool and dozens of its dependencies listed alongside your project’s packages. This creates “dependency soup,” where upgrading a library for one project could break a CLI tool, or vice versa. pipx, conversely, follows a fundamentally safer approach:

  1. It automatically creates a separate virtual environment for the application.
  2. It installs the application and all its dependencies into this isolated environment.
  3. It symlinks only the application’s entry-point scripts (e.g., black, mypy) into a central directory (like ~/.local/bin) that is on your system’s PATH. This means your global Python site-packages remains pristine, and each application is siloed away from the others and from your projects.

Installing pipx

pipx itself is a CLI tool that needs to be installed globally. The recommended method is via pip, but it can also be installed through system package managers.

# On macOS with Homebrew
brew install pipx

# On Ubuntu/Debian with apt
sudo apt install pipx

# On Windows with Chocolatey
choco install pipx

# Using pip (ensure you use a trusted source)
python3 -m pip install --user pipx

After installation, you must ensure the directory where pipx places symlinks is on your PATH. Typically, this is ~/.local/bin. You can configure this and add it to your shell’s configuration file (e.g., .bashrc, .zshrc) automatically.

pipx ensurepath

Installing and Running Applications

The primary command is pipx install. The syntax is straightforward and mirrors pip.

# Install the latest version of a package
pipx install cowsay

# Install a specific version
pipx install cowsay==5.0

# Install from a Git repository
pipx install git+https://github.com/psf/black

# Install from a local directory
pipx install ./my_cli_tool_package/

Once installed, you can run the application simply by typing its name in your terminal, as the executable is now available globally.

cowsay "Hello from my isolated environment!"
 _________________________
< Hello from my isolated environment! >
 -------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Managing Installed Applications

pipx provides a suite of commands to manage the lifecycle of your installed tools.

# List all applications installed with pipx and their executable paths
pipx list

# Upgrade a specific package to its latest version
pipx upgrade cowsay

# Upgrade all packages installed with pipx
pipx upgrade-all

# Uninstall an application and completely remove its virtual environment
pipx uninstall cowsay

# Run an application without installing it (great for one-off commands)
pipx run pycowsay "This is a temporary run"

Injecting Packages into an Existing App Environment

A powerful advanced feature of pipx is the ability to inject additional packages into an application’s isolated environment. This is useful if a CLI tool needs an optional plugin or a supporting library that wasn’t included by default.

# First, install the main application
pipx install black

# Now, inject the 'colorama' package into black's environment
pipx inject black colorama

This command modifies the virtual environment created for black, adding the colorama package without affecting any other environments or your global Python.

Common Pitfalls and Best Practices

A common pitfall is attempting to use pipx to install a library intended for import rather than a CLI application with console scripts. pipx will install it, but it won’t create any symlinks to run, making the installation largely useless. Use pip for libraries and pipx only for applications.

Best practices include:

  • Regular Upgrades: Use pipx upgrade-all periodically to keep your tools secure and up-to-date.
  • Leverage pipx run: For trying a tool once or in automation scripts where installation isn’t necessary, pipx run downloads, installs temporarily, and runs the tool in a single command.
  • Inspecting Environments: Use pipx list to see what you have installed and pipx run --verbose ... to debug what pipx is doing behind the scenes.
  • Understanding Limitations: pipx manages environments for applications. It is not a replacement for venv or poetry when managing dependencies for a project you are developing.