ModuleNotFoundError: No module named 'pip'

All of a sudden my (Python) glitch stopped working:

Traceback (most recent call last):
  File ".data/venv/bin/pip", line 5, in <module>
    from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip'

I deleted the venv and ran Now it’s working again.
What could have gone wrong?

A few thoughts:

  • pip is likely already distributed along with whatever built-in Python versions are in Glitch. It’s possible the module resolution for one version of Python was expecting to find a particular version of pip.
  • Your system environment may have been reset, e.g., your terminal session ended, and your PATH was subsequently reset. It’s a common mistake for folks to make transitive changes and forget to modify the PATH environment variable based on those changes.

It’s likely the latter occurred or some combination of the two. pip is very hard to deal with when there are multiple versions of Python installed because of the way module resolution works (or, rather, doesn’t work) in Python.

I just want to point out that your workflow is in no way flawed. You should be able to install pip in virtual environments and that version should work.

EDIT: There’s also pip3. I don’t know which version of Python you’re using but there might be a difference between the two if pip isn’t symbolically linked to pip3. Confusingly, I think Homebrew now distributes what it used to call python3 or python@3 as just python. The corresponding pip may or may not be aliased similarly. I can’t recall.

I guess something must have messed up the venv. I can’t think what though, as that app has been running fine for weeks on end. It was running fine last time I looked, and when I came back after a day or two, I saw this error. So it didn’t go wrong in response to me messing with the environment.
Thanks for the answer :slight_smile: