Pipx: Safely Install Packages Globally

Installing Python packages globally using pip can cause several issues. However, some packages are better installed globally on your system because they are tools you use daily. This is in contrast to your regular Python project dependencies, for which you would typically use something like uv or Poetry. This article explores the pipx tool and teaches you when it’s typically used.

Issues you may run into

Here are a few common issues that occur when you use pip install to install tools globally on your system:

  1. Dependency Conflicts: The most common problem is conflicting dependencies. For example, if two packages require different versions of the same dependency, installing both packages globally could cause one or both to break. This is also known as “dependency hell.”
  2. System Breakage: On some systems, certain system utilities rely on Python and its packages.
    • If you install a package globally and it updates or replaces a dependency used by a system utility, it can break that utility.
    • Vice versa: if you update your system, your globally installed package can break because it was installed for other Python versions and other versions of the dependencies.
  3. Difficulty Isolating Issues: When all packages are installed globally, it can be difficult to determine which package is causing a problem if something goes wrong.
  4. Not Easy to Remove or Update Packages: Uninstalling or updating a package can cause issues with other packages that depend on it. Removing a package does not remove its dependencies, leaving unused clutter on your system.
  5. Lack of Isolation: Global packages are available to all Python projects on your system, whether or not they need them, leading to potential version conflicts between projects.

There are multiple ways to prevent these issues, and they all involve using virtual environments. If you’re new to virtual environments, please click the link to read up on it first.

Identifying your problem

Before deciding which tool to use, we must identify the problem you’re trying to solve. Let’s define two main categories:

  1. Your Python project needs a dependency like FastAPI, Django, NumPy, or Requests
  2. You want to install a Python-based tool that you regularly start from the command line, like Jupyter Notebook, Poetry, or the Ruff linter

For the first type of problem, you should create a virtual environment to accompany your project. You can do so manually with python -m venv or use popular tools like uv or Poetry. For the second type of problem, pipx is your go-to tool! (Or uv’s uv tool command, which I compare with pipx further down.)

What is pipx?

pipx is a utility for installing and running Python applications in isolated environments. It’s a great tool for Python developers and users who want to try out different applications without worrying about dependency conflicts. Here are some of the advantages of using pipx:

  1. Isolation of Dependencies: Each application installed with pipx gets its own isolated environment, which means its dependencies won’t interfere with those of your other applications or your global Python environment. This reduces the risk of package conflicts.
  2. Safe Experimentation: Because each application has its own isolated environment, you can try out different applications or different versions of the same application without affecting your other installations.
  3. Global Access: Applications installed with pipx are accessible from anywhere on your system, just like applications installed globally with pip, but without the associated risks of package conflicts.
  4. Easy Uninstallation: If you no longer need an application, you can remove it completely and cleanly with a single command, and it won’t leave behind any clutter or unused dependencies.
  5. Run-Once Applications: pipx can run Python applications in a temporary environment, which is useful for running applications that you only need to use once and don’t want to install permanently.
  6. Keeps your System Clean: Since every package is isolated, your system Python environment remains clean and uncluttered.
  7. Manageable Upgrade/Downgrade: Each package installed with pipx can be easily upgraded or downgraded without affecting other packages.
  8. Safe for system Python: Installing packages globally with pip can risk breaking system utilities that depend on Python. Since pipx isolates packages, it avoids this risk.

All of these features make pipx a valuable tool for Python developers and users who want to maintain a clean, conflict-free system while still being able to install and use a variety of Python applications easily.

When pipx is typically used

In short, pipx is typically used to install and run Python tools and applications, while other tools focus on managing venvs and installing library dependencies for your Python projects. To get a better feeling of when to use pipx, here are some Python tools that you might install globally:

  1. Ruff: A very fast linter and code formatter. It replaces Flake8, isort and Black for most people.
  2. Black: A popular Python code formatter.
  3. Mypy: A static type checker for Python.
  4. Poetry: a tool for dependency management and packaging in Python.
  5. HTTPie: A command line HTTP client, a user-friendly cURL replacement.
  6. Glances: A cross-platform system monitoring tool.
  7. Jupyter: An open-source web application that allows the creation and sharing of documents that contain live code, equations, visualizations, and narrative text.
  8. yt-dlp: A command-line program to download videos from YouTube and other sites. It’s the maintained successor of the abandoned youtube-dl.
  9. Cookiecutter: A command-line utility that creates projects from project templates.

How to install pipx

There are a number of methods to install pipx, depending on your OS and the type of your Python installation. I advise you to read the official installation instructions for your OS, but here’s a short summary to get you started quickly.

Windows

On Windows, you can use the regular pip tool, through the py launcher, to install pipx for your user:

py -m pip install --user pipx
py -m pipx ensurepathCode language: Python (python)

The pip install step may warn that the pipx directory is not in your PATH. That’s fine: running pipx through py -m pipx works anyway, and the ensurepath command adds that directory and %USERPROFILE%\.local\bin to your search path. Don’t forget to restart your terminal session after these steps to apply the changes.

If you use the Scoop package manager, scoop install pipx followed by pipx ensurepath works too.

MacOS

On MacOS, you typically want to use Homebrew:

brew install pipx
pipx ensurepathCode language: Shell Session (shell)

We used the ensurepath command again to make sure pipx will be in your PATH.

Linux

On Linux, install pipx with your package manager. Your OS will keep pipx updated and secure. On Debian-like systems (Debian, Ubuntu, Mint):

sudo apt update
sudo apt install pipx
pipx ensurepathCode language: Shell Session (shell)

On Fedora, use sudo dnf install pipx, followed by pipx ensurepath. Homebrew works on Linux too, with the same commands as on macOS.

Don’t use pip install --user pipx on Linux. Most recent distributions, like Ubuntu 23.04+, Debian 12+ and Fedora 38+, mark the system Python as “externally managed” (PEP 668), and pip will refuse with an externally-managed-environment error. The distro package may be a bit older than the latest pipx release, but for everyday use that doesn’t matter.

How to use pipx

While the official documentation covers all the commands and options, I’ll only show you the most important ones here.

Install a package

You can install a new package with pipx install. For example, to install Ruff, you would use:

pipx install ruffCode language: Shell Session (shell)

This command installs the package in its own isolated environment, separate from your system Python and any other packages installed with pipx. The output tells you which commands are now available:

creating virtual environment...
installing ruff...
done! ✨ 🌟 ✨
  installed package ruff 0.17.4, installed using Python 3.13.13
  These apps are now available
    - ruffCode language: Python (python)

From now on, you can run ruff from any directory.

List installed packages

You can list all packages installed with pipx using the pipx list command:

pipx listCode language: Shell Session (shell)

This will give you a list of all the packages you’ve installed with pipx, along with their versions and the versions of Python they’re using.

Upgrade a package

If you want to upgrade a package to its latest version, you can use pipx upgrade. For example, to upgrade Ruff, you would use:

pipx upgrade ruffCode language: Shell Session (shell)

To upgrade everything you installed with pipx in one go, use pipx upgrade-all.

pipx upgrade-allCode language: Python (python)

Uninstall a package

If you decide you no longer need a package, you can uninstall it with pipx uninstall. For example, to uninstall Ruff, you would use:

pipx uninstall ruffCode language: Shell Session (shell)

Inject a package

If an application installed by pipx requires additional packages, you can add them with pipx inject. For example, if you have ipython installed and want to add the matplotlib package to it, you would use:

pipx inject ipython matplotlibCode language: Shell Session (shell)

Reinstall all packages

If you upgrade your system’s Python version and want all your pipx-installed packages to use the new version, you can use pipx reinstall-all:

pipx reinstall-allCode language: Python (python)

This is my personal favorite and a big time saver. Each time I update my Ubuntu installation, which is each half year, I have to fix all my globally installed Python tools. With pipx, it’s just this one command, and you’re all set!

Run a package

If you want to run a Python application in a one-off environment without installing it, you can use pipx run. For example, to run Ruff’s linter just once on a file named example.py, you would use:

pipx run ruff check example.pyCode language: Python (python)

As another example, let’s say you want to download a YouTube video using yt-dlp, but you don’t have yt-dlp installed on your system and don’t plan to use it frequently. You could use pipx run to execute yt-dlp in a temporary environment:

pipx run yt-dlp https://www.youtube.com/watch?v=<video_id>Code language: Python (python)

This command creates a temporary environment, installs yt-dlp in it, and downloads the video from the provided URL. pipx keeps the temporary environment in its cache for 14 days, so running the same command again soon after starts right away. After that, it builds a fresh one with the latest release.

pipx vs uv tool

pipx is no longer the only tool for this job. uv, the fast all-in-one Python tool from Astral, has the same feature built in with uv tool, plus the uvx shortcut for one-off runs. The commands map almost one to one:

What you wantpipxuv
Install a toolpipx install ruffuv tool install ruff
Run a tool oncepipx run yt-dlp ...uvx yt-dlp ...
List installed toolspipx listuv tool list
Upgrade a toolpipx upgrade ruffuv tool upgrade ruff
Upgrade everythingpipx upgrade-alluv tool upgrade --all
Uninstall a toolpipx uninstall ruffuv tool uninstall ruff
Add a package to a toolpipx inject ipython matplotlibuv tool install ipython --with matplotlib
Fix the PATHpipx ensurepathuv tool update-shell

So which one should you pick? If you already use uv for your projects, use uv tool. It’s faster, and you have one tool less to install and keep up to date. uv can also download the Python version a tool needs, so it doesn’t depend on the Python installed on your system.

pipx is still a fine choice if you don’t use uv, or if you prefer a tool maintained by the Python Packaging Authority that’s available in every Linux distribution. Recent pipx versions even use uv under the hood to create environments when they find it on your system. For the details, see the uv tools guide and the pipx documentation.

Related articles

Leave a Comment