In Python, ensuring package isolation is crucial to prevent conflicts with one another, and to achieve this goal, there are several tools available, including
pipx (our topic for today).
Before going more in-depth on
pipx, let’s first address the differences among
pipx to prevent any confusion and clarify their respective purposes.
virtualenvis a tool for creating isolated Python environments where you can install packages and dependencies specific to a particular project.
pipenvis a higher-level tool that combines package management (with
pip) and virtual environment management (with
virtualenv) into a single, user-friendly interface. It aims to simplify dependency management for Python projects.
pipxis primarily designed for installing and executing Python applications as if they were standalone command-line tools. It provides a convenient way to isolate and manage these applications in separate environments.
As you grasp their intended purposes, the difference may become clearer. For a sharper understanding, I recommend checking the following use cases:
virtualenvtypically used when working on multiple Python projects that have different dependencies or when you need complete control over your Python environment.
pipenvtypically used when you want a streamlined way to manage project-specific dependencies, including both packages and the virtual environment, in a single tool.
pipxtypically used when you want to install Python programs that you intend to run as command-line tools, keeping them separate from your main Python environment and other projects.
I hope you’ve understood the difference among these virtual isolation tools. Now, let’s understand what exactly
pipx is, how to install it, and its usage.
|Root or Sudo Privileges
|Yes (for installation)
|Ubuntu, Manjaro, Fedora, etc.
What is Pipx in Python?
Pipx is a fantastic tool that lets you install Python applications in isolated environments, making them globally accessible from your terminal, just like standard Linux commands such as ls, cat, and ps.
Especially helpful when you plan to use specific Python applications, such as “
numpy” or “
neofetch“, as standalone programs and also within your Python project.
To prevent conflict, an isolated environment is created for each Python application you install via
pipx, making sure they don’t make a mess with each other on your main Python setup.
Let’s see how to install and use
pipx on your preferred Linux distributions.
How to Install Pipx on Linux
Pipx can be easily installed using “
pip” without requiring root privileges, but I usually avoid this method due to the multiple configuration steps involved.
I’d prefer you to use one of these commands to install it with the system package manager:
$ sudo apt install pipx #For Ubuntu, Debian, Linux Mint
$ sudo dnf install pipx #For RHEL, Fedora, AlmaLinux
$ sudo pacman -S python-pipx #For Arch, Manjaro, EndeavorOS
After completing the installation, execute the following command to add the local bin path to your
$PATH environment variable:
$ pipx ensurepath
Restart your terminal session now to implement the changes, and then proceed to the next section for instructions on how to use it.
Usage of the Pipx Command
In this section, you’ll learn how to use the
pipx command to search, install, list installed packages, update, or remove packages. So, let’s begin with…
Installing packages with
pipx is a breeze – just use the “
pipx install” command followed by your desired package name, as shown.
$ pipx install cowsay
After the installation, you can test that the installed packages are running as a standalone application by using the following command:
$ cowsay -t "Hello, World!"
When you want to install a particular package version, just specify the desired version followed by “
==“, as shown.
$ pipx install numpy==1.25.2
Listing Installed Packages
The following command will give you a list of all the packages installed via the
$ pipx list
Pipx lacks an integrated search function due to PyPi API usage restrictions, but this doesn’t mean you can’t do that; you can use
pypisearch for searching packages.
To search packages, install
pypisearch by running the following command:
$ pipx install pypisearch
Once the installation is complete,
pypisearch will be available as a standalone application, and you can easily search for packages by specifying their name as an argument to this command.
$ pypisearch neofetch
Like the traditional package manager,
pipx allows you to upgrade all the packages at once using the following command:
$ pipx upgrade-all
In my system, all packages are currently up-to-date, resulting in no changes. However, in your case, it will start the package upgrade process with the available updates.
Alternatively, you can also upgrade specific package (let’s say “
cowsay“) to the latest version by using the following command:
$ pipx upgrade cowsay
To remove a package, just specify the package name in the “
pipx uninstall” command, as shown.
$ pipx uninstall numpy
How to Remove Pipx from Linux
If you think that this tool isn’t as helpful, you can easily uninstall it from your system using one of the following commands:
$ sudo apt remove pipx #For Ubuntu, Debian, Linux Mint
$ sudo dnf remove pipx #For RHEL, Fedora, AlmaLinux
$ sudo pacman -R python-pipx #For Arch, Manjaro, EndeavorOS
I hope you find this article useful, and don’t forget to leave your thoughts or opinions related to this tool, including your queries.
Till then, peace!