Ticker

6/recent/ticker-posts

Ad Code

Responsive Advertisement

Install and Use pipx in Linux

Install and Use pipx in Linux

Pip is a popular tool for installing Python packages and modules from Python Package Index.

However, in recent distribution versions, pip users are encountering an externally-managed-environment error.

Install and Use pipx in Linux

That's a 'feature' added to avoid conflicts between Python packages installed via Pip and the native package manager. Python wants you to use separate virtual environments instead of installing the package at the global level via Pip.

This is where pipx comes into the picture. It creates a new virtual environment for each application you install and then creates links to local binary in the /bin at the global level. All this is automatic. It saves time and effort for you.

Let's see how to install and use Pipx on Ubuntu and other Linux distributions.

Install pipx on Ubuntu and other Linux

The installation is straightforward and can be installed using the following command on Ubuntu and Debian:

sudo apt update && sudo apt install pipx

For other distributions, please use your package manager and install it.

Once you are done with the installation, add it to the $PATH so it can be accessed from everywhere:

pipx ensurepath
Install and Use pipx in Linux

Close the terminal and start it again. That's it! Now, let's have a look at how to use it.

Using pipx

What is the primary use of a package manager? Package installation, updation, and removal.

Let me show how you can do the following with pipx:

  • Search packages
  • Package installation
  • Upgradation
  • Package removal

Let's start with the installation.

How to install packages using pipx

To install packages using pipx, you'd have to follow a simple command syntax:

pipx install <package_name>

For example, here, I installed a very useful program Cowsay:

pipx install cowsay
Install and Use pipx in Linux

Similarly, if you want to install a specific version of the package, you'd have to insert the version number followed by == as shown:

pipx install package==version

For example, here, I installed numpy version 1.24.1:

pipx install numpy==1.24.1
Install and Use pipx in Linux

How to search packages

The pipx utility does not have a search feature (because of limited API use of PyPI) but that doesn't mean you can't search Python packages.

To search packages, you'd have to install pypisearch:

pipx install pypisearch

Once you do that, you can search the packages using the pypisearch command:

pypisearch python_package_name

Here, I searched for neofetch:

Install and Use pipx in Linux

How to upgrade packages using pipx

Like any other modern package manager, you can upgrade all packages at once or you can upgrade one package at a time.

To upgrade all the packages at once, all you have to do is execute the following command:

pipx upgrade-all
Install and Use pipx in Linux

As you can see, it upgraded numpy to the latest version.

But if you want to upgrade a specific package, here's how you do it:

pipx upgrade package-name

Let's say I want to upgrade cowsay package to the latest version, then, I will be using the following:

pipx upgrade cowsay
Install and Use pipx in Linux

How to uninstall packages using pipx

To remove packages, you'd have to use the uninstall flag as shown:

pipx uninstall package_name

For your reference, here, I removed numpy from my system:

pipx uninstall numpy
Install and Use pipx in Linux

Pip or Pipx?

The restrictions put on Pip have limited its use by the end users. Thankfully, Pipx provides the much-needed alternative. It meets the Python guidelines of using virtual environments and, at the same time, allows installed applications to be available at the global level.

For end users, who are not Python application developers, this gives the option to use Python applications unavailable in distribution repositories.

I hope you find this tutorial helpful. Let me know if you have questions or suggestions.

Enregistrer un commentaire

0 Commentaires