Skip to content

updating setuptools causes pip to no longer import as a module successfully #10737

Closed
@kevinushey

Description

@kevinushey

Description

After upgrading setuptools, I'm no longer able to import pip as a module within a Python REPL. This is on macOS, using Python 3.9.9 from Homebrew.

/opt/homebrew/bin/python3 -m venv /tmp/venv
/tmp/venv/bin/python -m pip install --upgrade setuptools
/tmp/venv/bin/python -c 'import pip; print(pip.__version__)'

Running this, I see:

$ /tmp/venv/bin/python -c 'import pip; print(pip.__version__)'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 982, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 925, in _find_spec
  File "/private/tmp/venv/lib/python3.9/site-packages/_distutils_hack/__init__.py", line 83, in find_spec
    return method()
  File "/private/tmp/venv/lib/python3.9/site-packages/_distutils_hack/__init__.py", line 104, in spec_for_pip
    if self.pip_imported_during_build():
  File "/private/tmp/venv/lib/python3.9/site-packages/_distutils_hack/__init__.py", line 115, in pip_imported_during_build
    return any(
  File "/private/tmp/venv/lib/python3.9/site-packages/_distutils_hack/__init__.py", line 116, in <genexpr>
    frame.f_globals['__file__'].endswith('setup.py')
KeyError: '__file__'

Expected behavior

Ideally, pip should load as a module without issue.

pip version

21.3.1

Python version

3.9.9

OS

macOS 12.1

How to Reproduce

See above.

Output

See above.

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    project: setuptoolsRelated to setuptoolstype: bugA confirmed bug or unintended behavior

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions