With pipx, you can install a Python-based command line tool in a manner that is safe, stable, and convenient. It is like Node/npm's npx, but for Python. In other words, it is a package runner. It installs the requested package, but in an isolated environment with the correct dependencies, so you can run the associated script(s) as command line tools.
pipxdoes not replace
pipor virtual environments. For normal Python development, use virtual environments and
pipor use a tool like Poetry. What
pipxprovides is isolation and convenience. In fact,
pipxuses virtual environments and
pipto accomplish these goals.
pipx allows you to install useful command line tools like
$ pipx install virtualenv installed package virtualenv... done! $ virtualenv usage: virtualenv...
I have included step-by-step instructions in this article, but the official installation instructions are here.
If you understand your platform, and already have Python 3 installed, this should install pipx:
python3 -m pip install --user pipx python3 -m pipx ensurepath
py -3 or whatever gets you a decent Python 3 interpreter.
pipx ensurepath includes
pipx in your PATH variable. In other words, this makes sure that entering
pipx by itself will find the right executable.
Do you have Homebrew? If not, install it with this:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Because using a Mac without Homebrew is like
See the Homebrew homepage for more detail.
brew install pipx
First, install Python. Various ways to do that. If unsure, go to python.org and download and run the installer.
Once installed, launch Powershell and then follow the generic directions above.
I did have a bit of trouble with PATH and Windows. I think this was resolved when I closed my Windows Terminal (all tabs) and restarted it... Who am I kidding. I just rebooted Windows, because that is what you do.
I made sure that these two were in my PATH environment variable:
- Because I installed pipx using
pip install --user, the
pipxexecutable was in
pipx-installed executables are in
Your package manager (such as
dnf) may have
pipx in the repositories somewhere, so that
apt install pipx or
dnf install pipx should work.
Otherwise, make sure you have Python 3 installed, then, if your distro weirdly separates out
venv, make sure you install packages like
Then follow the generic directions above.
python -m pip shows an error like "The virtual environment was not created successfully because ensurepip is not available," follow the instructions given or install pip and venv following the official guide.
Because systems are all different, and often customized, there is a slim chance that
pipx ensurepip doesn't change the PATH environment variable permanently. Or you might simply be someone who wants to handle this setting yourself, rather than running
Setting the PATH variable on Windows is explained above.
On Linux, Mac, and other Unix-like systems, check the PATH variable with:
You should see a colon-separated list of filesystem paths, in which various executables reside. If
/home/your_username/.local/bin is in that list, you are golden.
If you need to edit the PATH variable, there will be a file or files in your home directory in which to set it. I would suggest checking the files in this order:
You can edit any of these with the text editor of your choice. If you are not sure what to use, try
nano from the command line. If you know Vim, try
vi but beware that twenty years from now you may still be using Vim because you don't know how to quit.
The line you want to add or edit is:
If you use
zsh, you could get away with
Here are some
pipx commands I find useful:
pipx install youtube-dl- installs a new package, in this example, "youtube-dl" (hmmm... I wonder what that package does)
pipx upgrade virtualenv- this upgrades a specific package. In this example, the package "virtualenv" is upgraded
pipx upgrade-all- upgrades all packages installed with
pipx list- shows all the packages installed and path information
pipx run youtube-dl- temporarily downloads, installs, and runs the package "youtube-dl" without affecting your environment
I hope you find these examples useful!