Ceci est une ancienne révision du document !
pipx???
Greetings again fellow Sentient Lifeforms and, as Dr. Johnny Fever would say, “Fellow Babies”. Once again, I’m beaming from landing pad 2997 on Terra to bring you more information on Python and its related goodies, add-ons, tips, tricks, traps, and other weirdness.
This month, we will be talking about pipx. Right about now, I’m sure you are thinking, “What the HECK is pipx, and is Greg having problems typing ‘pip’?” Well, the answer, to the last part first, is yes, Greg IS having problems typing, but that’s a story for another day!
Pipx IS REAL. Pipx, according to their website, allows you to “Install and Run Python Applications in Isolated Environments”. Now isn’t that about as clear as mud?
So let’s open a browser and look at https://github.com/pypa/pipx/tree/main?tab=readme-ov-file, which is the pipx distribution site, and scroll about ⅓ of the way down the page, or search that page for “what is pipx”.
According the the web page: “pipx is a tool to help you install and run end-user applications written in Python. It's roughly similar to macOS's brew, JavaScript's npx, and Linux's apt.
It's closely related to pip. In fact, it uses pip, but is focused on installing and managing Python packages that can be run from the command-line directly as applications.”
In fact, if you dig deeper, you will find this statement: “pipx is a specialized package installer. It can be used to install only packages with cli entry points.”
Now that makes things much clearer. So how do you install such a thing?
There are two ways to install pipx on a Linux machine. The first is via apt, and the other is via (guess what) pip.
So we’ll look at the apt method first. Assuming you are running Ubuntu 23.04 or above (or a distro based on that)…
sudo apt update
sudo apt install pipx
pipx ensurepath
sudo pipx ensurepath –global # optional to allow pipx actions with –global argument
If, however, you want to install via pip(3)…
pip install pipx
You might want to run the last two lines from the apt install section above, after you've installed via pip – to make sure pipx is available from pretty much anywhere on your system.
pipx ensurepath
sudo pipx ensurepath –global # optional to allow pipx actions with –global argument
Ok. It’s installed. Now what?
We’ll take a look at some of the command-line options to help us out here.
If you don’t know what to do, you can always ask for help…
pipx -h
~/Desktop$ pipx -h usage: pipx [-h] [–version]
{install,inject,upgrade,upgrade-all,uninstall,uninstall-all,reinstall,reinstall-all,list,run,runpip,ensurepath,completions}
...
Install and execute apps from Python packages.
Actually, I’m breaking the terminal output here to save space (more shown on the next page, top right).
And it keeps going, so I’m going to just leave it at this. The important commands (at least for me) are list, install, and uninstall.
So let’s install something. We’ll use the silly pycowsay program as our example.
pipx install pycowsayinstalled package pycowsay 2.0.3, Python 3.10.3 These apps are now globally available - pycowsaydone!
Now that you have something installed, let’s try doing a list.
greg@Earth2:~/Desktop$ pipx list venvs are in /home/greg/.local/pipx/venvs apps are exposed on your $PATH at /home/greg/.local/bin
package pycowsay 0.0.0.2, installed using Python 3.10.12 - pycowsay
Now, we can run the pycowsay program without calling Python directly or even using the .py extension.
greg@Earth2:~/Desktop$ pycowsay “Howdy fellow beings! Good to see you again!”
< Howdy fellow beings! Good to see you again! >
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
greg@Earth2:~/Desktop$
As I said. It’s a silly program. But it’s a pretty good test.
Another feature of pipx is that it can download and run an application in a temporary virtual environment without installing the application. You can use the pipx run command:
greg@Earth2:~/Desktop$ pipx run pycowsay moo
Now I’ve already installed pycowsay into pipx, so it will complain at me just a little bit, but will still download and run it.
pycowsay is already on your PATH and installed at /home/greg/.local/bin/pycowsay. Downloading and running anyway.
- –
< moo >
- –
\ ^^ \ (oo)\_
(__)\ )\/\
||----w |
|| ||
What happens if you try to install a program that doesn’t have an entry point, or has a name that doesn’t match the actual filename? The esptool package is a good example of this. I use this package to flash some of the esp microcontrollers that I have.
First, we’ll try to run just normally, but not install it (next page, top right).
You can see that there are four different applications that seem to be associated with the name “esptool”.
To get around that, we can use the –spec option with the name of the program.
greg@Earth2:~/Desktop$ pipx run –spec esptool esptool.py esptool.py is already on your PATH and installed at /home/greg/.pyenv/shims/esptool.py. Downloading and running anyway.
Again, I’ve already got it loaded, but pipx will download the latest version and then run it in a virtual environment for me. There is a LOT of terminal output so I’ll just pick some to show that it really runs (next page, bottom right).
There are SO many reasons to give pipx a try.
Again, their website is https://github.com/pypa/pipx.
Until next time, as always; stay safe, healthy, positive and creative!
