Open In App

Pipx : Python CLI package tool

In this article, we will explore the basics of pipx python CLI package tool. Pipx is a tool in Python that allows us to run python packages that have a CLI interface in the global context of your system. It uses its own environment for managing the packages.

Here, we will cover its installations, setting up its environment, and how we can uninstall packages. This can be done by following the step by step instructions provided below:



Downloading and Installing Pandas

Now run the following command:

pip install pipx

 

pipx has the following available command options:



pipx

optional environment variables:

Optional arguments:

Subcommands: Get help for commands with pipx COMMAND –help

Install a package with CLI support

To install any package which has a Command-line Interface, we need to simply use the install command with pipx

pipx install <package_name>

Example 1:

Let’s say we want to run the httpie package from anywhere on our system. We can install the package with pipx.

pipx install httpie

 

This will install httpie package in its own environment, not a single environment for pipx but a separate virtual environment for each package we install with pipx. So we basically have access to these packages via pipx anywhere on our system.

Example 2:

Let’s install one more package with pipx

pipx install black

 

Path of packages installed

Now, once we have a couple of packages installed with pipx, we can see the path of PIPX_HOME directory where it has stored all of its packages in its own virtual environments.

 

As we can see the PIPX_HOME directory is in the ~/.local/pipx/venvs

This folder will store all the virtual environments whose packages have been installed via pipx. Each package has its own virtual environment, so we can run packages in an isolated environment. 

Pipx list command

We can even list out all the installed packages with pipx. We can use the list command to display and check which packages and commands we can run with pipx.

pipx list

 

Run commands with pipx for packages

Once we have a few packages installed and set up with pipx, we can try running them via pipx. Remember that the packages need to have a CLI to interact and enter commands in the shell/CMD. Pipx will also install those packages whose apps/executables can be run within a CLI environment. 

To run a command with the package in pipx, you simply need to parse the run command along with the parameters associated with the particular command or package.

pipx run black script.py

 

Demonstrated by running the same command at other places:

 

Uninstall packages with pipx

We can even uninstall the packages in pipx, the command will remove the package from the global context that pipx uses to run the command in that package’s virtual environment. 

pipx uninstall httpie

 

Article Tags :