Install and use pipx in Ubuntu and other Linux systems


Pip is a popular tool for installing Python packages and modules from Python package index.

However, on recent distribution releases, pip users encounter the Externally managed environment error.

Error: Externally managed environment

This “feature” was added to avoid conflicts between installed Python packages via a point and native package manager. Python wants to use separate virtual environments instead of installing the package globally via Pip.

This is where the point comes into the picture. It creates a new virtual environment for each application you install and then creates links to a local binary in /bin on the global level. It’s all 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 systems

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

sudo apt update && sudo apt install pipx

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

Once the installation is completed, Add it to $PATH So it can be accessed from anywhere:

pipx ensurepath
install pipx in ubuntu

Turn off the device and start it up again. That’s it! Now, let’s take a look at how to use it.

using pipx

What is the primary use of a package manager? Install, update, and remove the package.

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

  • search packages
  • Package installation
  • upgrade
  • Remove the package

Let’s start with the installation.

How to install packages with Pipx

To install packages with pipx you have to follow a simple command syntax:

pipx install <package_name>

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

pipx install cowsay
Installing python packages in isolation using pipx in Ubuntu

Similarly, if you want to install a specific version of the package, you will have to enter 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

How to search for packages

pipx does not have a search feature (due to limited use of the PyPI API) but that doesn’t mean you can’t search Python packages.

To search for packages, you must install pypisearch:

pipx install pypisearch

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

pypisearch python_package_name

Here, I searched for neofetch:

Find python packages in Ubuntu

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 packages at once, all you need to do is execute the following command:

pipx upgrade-all
Upgrade all python packages at once in ubuntu

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

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

pipx upgrade package-name

Let’s say I want to upgrade cowsay package to the latest version, then I would use the following:

pipx upgrade cowsay
Upgrade a specific python package using pipx in Ubuntu

How to uninstall packages with Pipx

To remove packages, you have to use a file uninstall Flag as shown:

pipx uninstall package_name

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

pipx uninstall numpy
Remove python packages using pipx in Ubuntu

Pip or Pipx?

The limitations of Pip have limited its use by end users. Fortunately, Pipx provides the much needed alternative. It fulfills Python’s guidelines for using virtual environments, and at the same time, allows installed applications to be available globally.

For end users, who are not developers of Python applications, this provides the option of using Python applications that are not available in the distribution repositories.

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



Source link

Leave a Comment

Your email address will not be published. Required fields are marked *