Pipx: No module named pip

Created on 16 Nov 2019  ยท  9Comments  ยท  Source: pipxproject/pipx

Opening this ticket because I think it could help others. Also, not pipx's fault :+1:!

My distribution recently updated Python from 3.7.x to 3.8.0. It broke every single package I had installed with pipx somehow, and pipx itself.

I was left with these kind of errors:

$ guessit "some string"
Traceback (most recent call last):
  File "/home/pawamoy/.local/bin/guessit", line 5, in <module>
    from guessit.__main__ import main
ModuleNotFoundError: No module named 'guessit'
$ pipx install guessit
Traceback (most recent call last):
  File "/home/pawamoy/.local/bin/pipx", line 6, in <module>
    from pipx.main import cli
ModuleNotFoundError: No module named 'pipx'
$ pip install --user pipx
$ pipx install guessit
'guessit' already seems to be installed. Not modifying existing installation in '/home/pawamoy/.local/pipx/venvs/guessit'. Pass '--force' to force installation.
$ pipx install guessit --force
Installing to existing directory '/home/pawamoy/.local/pipx/venvs/guessit'
/home/pawamoy/.local/pipx/venvs/guessit/bin/python: No module named pip

Not removing existing venv /home/pawamoy/.local/pipx/venvs/guessit because it was not created in this session
'/home/pawamoy/.local/pipx/venvs/guessit/bin/python -m pip install guessit -q' failed
$ guessit
Traceback (most recent call last):
  File "/home/pawamoy/.local/bin/guessit", line 5, in <module>
    from guessit.__main__ import main
ModuleNotFoundError: No module named 'guessit'
$ pipx uninstall guessit
uninstalled guessit! โœจ ๐ŸŒŸ โœจ
$ pipx install guessit
/home/pawamoy/.local/pipx/venvs/guessit/bin/python: No module named pip

'/home/pawamoy/.local/pipx/venvs/guessit/bin/python -m pip install guessit -q' failed

Not sure what exactly was happening behind the scenes as it's always hard to figure out with Python: there's the system versions, with their respective site-packages, there's pyenv and its own installed versions and shims, then there's potentially multiple pipx (shims?) and a script in ~/.local/bin (which one is the first in PATH?)... very convoluted but usually working.

Solution

Well, I simply had to explicitly uninstall pipx from the old system Python version with python3.7 -m pip uninstall pipx and then reinstall it with the new system Python version with python -m pip install --user pipx, and reinstall all pipx packages.

Most helpful comment

I had the same problem, but was not able to use Python 3.7 to uninstall pipx.

I resolved this by uninstalling pipx, deleting ~/.local/pipx, and reinstalling pipx with the new version of Python.

All 9 comments

I had the same problem, but was not able to use Python 3.7 to uninstall pipx.

I resolved this by uninstalling pipx, deleting ~/.local/pipx, and reinstalling pipx with the new version of Python.

Thanks, in fact I stumbled upon that problem again, and your solution worked.

Removing ~/.local/pipx and reinstalling pipx also worked for me! Thanks.

Happened to me today too. Are you sure it's not an issue of pipx if it cannot survive python version upgrades?

Presently if you still have a functioning pipx but the pipx-installed apps are pointing to a non-existent python, you should be able to execute

pipx reinstall-all

To make things right.

pipx has improved its resilience in this regard since Nov. 2019.

Arch Linux just updated its python package to v3.9 and pipx borked for me.

First, I tried listing installed packages:

$ pipx list
Traceback (most recent call last):
  File "/home/gui/.local/bin/pipx", line 6, in <module>
    from pipx.main import cli
ModuleNotFoundError: No module named 'pipx'

Then, I reinstalled pipx:

$ pip install --user pipx
Collecting pipx
  Downloading pipx-0.15.6.0-py3-none-any.whl (43 kB)
     |โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 43 kB 1.1 MB/s 
Collecting userpath>=1.4.1
  Downloading userpath-1.4.1-py2.py3-none-any.whl (14 kB)
Requirement already satisfied: packaging>=20.0 in /usr/lib/python3.9/site-packages (from pipx) (20.7)
Collecting argcomplete<2.0,>=1.9.4
  Downloading argcomplete-1.12.2-py2.py3-none-any.whl (38 kB)
Requirement already satisfied: click in /usr/lib/python3.9/site-packages (from userpath>=1.4.1->pipx) (7.1.2)
Requirement already satisfied: distro; platform_system == "Linux" in /usr/lib/python3.9/site-packages (from userpath>=1.4.1->pipx) (1.5.0)
Requirement already satisfied: pyparsing>=2.0.2 in /usr/lib/python3.9/site-packages (from packaging>=20.0->pipx) (2.4.7)
Installing collected packages: userpath, argcomplete, pipx
Successfully installed argcomplete-1.12.2 pipx-0.15.6.0 userpath-1.4.1

... Tried to list my packages again:

$ pipx list
venvs are in /home/gui/.local/pipx/venvs
apps are exposed on your $PATH at /home/gui/.local/bin
   package jsbeautifier has missing internal pipx metadata.
       It was likely installed using a pipx version before 0.15.0.0.
       Please uninstall and install this package, or reinstall-all to fix.
   package mitmproxy has missing internal pipx metadata.
       It was likely installed using a pipx version before 0.15.0.0.
       Please uninstall and install this package, or reinstall-all to fix.
   package youtube-dl has missing internal pipx metadata.
       It was likely installed using a pipx version before 0.15.0.0.
       Please uninstall and install this package, or reinstall-all to fix.

As suggested by pipx, I tried running pipx reinstall-all:

$ pipx reinstall-all
uninstalled jsbeautifier! โœจ ๐ŸŒŸ โœจ
/home/gui/.local/pipx/venvs/jsbeautifier/bin/python: No module named pip

Error installing jsbeautifier.
uninstalled mitmproxy! โœจ ๐ŸŒŸ โœจ
/home/gui/.local/pipx/venvs/mitmproxy/bin/python: No module named pip

Error installing mitmproxy.
uninstalled youtube-dl! โœจ ๐ŸŒŸ โœจ
/home/gui/.local/pipx/venvs/youtube-dl/bin/python: No module named pip

Error installing youtube-dl.
The following package(s) failed to reinstall: jsbeautifier, mitmproxy, youtube-dl

Having that failed, I tried to manually install an app:

$ pipx install jsbeautifier
/home/gui/.local/pipx/venvs/jsbeautifier/bin/python: No module named pip

Error installing jsbeautifier.

Trying to list my apps again...:

$ pipx list
nothing has been installed with pipx ๐Ÿ˜ด

Did I do something wrong? I haven't deleted my ~/.local/pipx folder yet, by the way, so pipx is still broken.

I'll wait for a response first in case this can help fix something.

@guihkx I don't think you did anything wrong. I believe the problem you are experiencing should be fixed in an upcoming release with #554 .

I think what happened was that after reinstalling pipx, the "shared libraries" that pipx uses internally to provide pip and other useful packages (~/.local/pipx/shared) were still stuck at the previous version and therefore unavailable to the new python / pipx. The default behavior in the next release will be to reinstall these shared libraries first before attempting to reinstall all the venvs.

Unfortunately, reinstall-all has uninstalled all of your venvs without being able to install any of them, so your ~/.local/pipx/venvs directory is probably empty. โ˜น๏ธ Therefore if you want to start over by deleting ~/.local/pipx you will most likely not lose anything. Sorry.

Don't worry, it's not an issue for me having to delete everything and install it again.

Thanks for the explanation too!

I'm having the same error as @guihkx .
@itsayellow is right , I believe the only folder we need to delete is ~/.local/pipx/shared/ .

I _think_ pipx will recreate them at the first (re)install, but I cannot prove it because I also ended up with reinstall-all uninstalling everything, but it is no big deal.

Was this page helpful?
0 / 5 - 0 ratings