pipx#
The pipx tool allows to install and run Python command-line applications with pip in isolated virtual environments. As such it fulfils a rather precise goal and should not be confused with the general-purpose installations of pip
and development tools like pipenv
or poetry
.
Motivation#
Besides the Python packages that install some libraries to be used inside your Python code, there are others that install command-line tools. Noteworthy examples are black
and flake8
, but also projects like ansible (to automate the configuration of a computer) or cookiecutter (to generate a project’s file structure from a template) . These tools are often used outside of a given Python programming project and its dependency management system.
The naive approach to make them available globally across projects is to install them with pip
. But if multiple packages are installed, you may run into issues of dependencies with mutually incompatible versions. Similarly to our previous discussion of virtual environments, a possible solution is to install each application into a dedicated venv. This is exactly what pipx
does.
Usage#
The following command installs a given package with pipx
.
$ pipx install <package>
Behind the scenes pipx
creates a folder structure inside ~/.local/pipx/
to contain the virtual environments for each installed application. The executables are linked into ~/.local/bin/
. To make the tools available in the shell, add this directory manually to your $PATH
or issue the pipx ensurepath
helper command.
The already installed packages and associated command-line tools can be listed.
$ pipx list
venvs are in ~/.local/pipx/venvs
apps are exposed on your $PATH at ~/.local/bin
package black 23.3.0, Python 3.11.2
- black
- black-primer
- blackd
Other commands include
$ pipx uninstall <package> # remove an installed package
$ pipx upgrade <package> # upgrade an installed package
$ pipx upgrade-all # upgrade all installed packages
$ pipx reinstall-all # reinstall all packages (eg to fix issues after python upgrades)
$ pipx inject <package> <pkg> # install additional pkg into existing venv of installed package