How To Fix pipx: Fatal Error From pip Prevented Installation / No Module Named pip


After upgrading from Ubuntu 22.10 to 23.04, pipx broke on my laptop and fixing it was not exactly straight-forward, so I thought I'd write here about this, in case there are others running into this issue. While I ran into this issue on Ubuntu, this isn't Ubuntu-specific, and it can happen on other Linux distributions as well.

pipx is a tool that makes it easy to install (using PyPI as the package index) isolated Python applications. pip is a Python package installer for both libraries and apps, while pipx is made specifically for applications, creating an isolated environment for each app and its dependencies.

Ubuntu 23.04 no longer allows pip installs outside a virtual environment, so using pipx is kind of a must if you want to install python apps that aren't available in the official repositories. I was using pipx for a while, but after upgrading to Ubuntu 23.04, I got the following error when trying to install a Python package using pipx:

$ pipx install yewtube

Fatal error from pip prevented installation. Full pip output in file:

/home/logix/.local/pipx/logs/cmd_2023-05-04_20.45.55_pip_errors.log

Error installing yewtube.

$ cat /home/logix/.local/pipx/logs/cmd_2023-05-04_20.45.55_pip_errors.log

/home/logix/.local/pipx/venvs/frogmouth/bin/python: No module named pip

It appears this happens when the Python version is upgraded (to a major version) on a machine on which pipx was installed and used before.

The best solution I could find to solve this issue is to remove the ~/.local/pipx/shared folder (or you can move it somewhere if you wish), which holds shared pipx libraries, then get pipx to reinstall the shared libraries. This can be done from the command line, using:

mv ~/.local/pipx/shared ~/.local/pipx/shared.old

pipx list

The mv command from above moves the ~/.local/pipx/shared folder to a new name, ~/.local/pipx/shared.old. The pipx list command lists installed packages, but if the shared libraries are missing, it installs them first, which is our case.

For me, this fixed the pipx install error, and my already installed pipx packages continued to work. In case your already installed pipx packages don't work, you can try to reinstall them using pipx reinstall-all, but do note that this may uninstall packages that it can't reinstall!

thanks to remcoboerma for the fix!