Search code examples
pythonpip

Python 3.11 with no builtin pip module - what's going on?


.venv/bin/python -m pip uninstall mysqlclient
/Users/anentropic/dev/project/.venv/bin/python: No module named pip

and

.venv/bin/python
Python 3.11.5 (main, Sep 18 2023, 15:04:25) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pip
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pip'

I thought pip was a builtin for recent Python versions, how is it that I have one where it doesn't exist?


Solution

  • So...

    pip isn't actually a "builtin" in recent Python versions

    What changed is it began to be bundled with Python installs by default, so it's usually available but not necessarily.

    For whatever reason (perhaps because my venv was created by pdm) mine did not come with it.

    This can be fixed by:

    .venv/bin/python -m ensurepip
    

    which installs it

    After that .venv/bin/python -m pip install etc work ok.