Skip to content

fix: Fix ModuleNotFoundError when pip is not installed#898

Merged
henryiii merged 2 commits intopypa:mainfrom
mgorny:fix-pip-vendor-check
May 21, 2025
Merged

fix: Fix ModuleNotFoundError when pip is not installed#898
henryiii merged 2 commits intopypa:mainfrom
mgorny:fix-pip-vendor-check

Conversation

@mgorny
Copy link
Contributor

@mgorny mgorny commented May 21, 2025

Fix the exception raised if pip is not installed at all:

[...]
  File "/usr/lib/python3.14/site-packages/build/env.py", line 168, in _has_valid_outer_pip
    if importlib.util.find_spec('pip._vendor') is None:
       ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "<frozen importlib.util>", line 90, in find_spec
ModuleNotFoundError: No module named 'pip'

This is a regression from #861 where I did not predict that find_spec() will actually raise when the parent package is not available. To fix it, just reorder the conditions to make sure that pip is installed first.

Fix the exception raised if `pip` is not installed at all:

```
[...]
  File "/usr/lib/python3.14/site-packages/build/env.py", line 168, in _has_valid_outer_pip
    if importlib.util.find_spec('pip._vendor') is None:
       ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "<frozen importlib.util>", line 90, in find_spec
ModuleNotFoundError: No module named 'pip'
```

This is a regression from pypa#861 where I did not predict that
`find_spec()` will actually raise when the parent package
is not available. To fix it, just reorder the conditions to make sure
that `pip` is installed first.
@henryiii henryiii force-pushed the fix-pip-vendor-check branch from 301b492 to 5480b7c Compare May 21, 2025 20:17
@henryiii
Copy link
Contributor

Ah, I think this was a regression in an unreleased change? Best kind of fix. :)

@henryiii henryiii merged commit 6c66d0f into pypa:main May 21, 2025
64 checks passed
@mgorny
Copy link
Contributor Author

mgorny commented May 22, 2025

Ah, I think this was a regression in an unreleased change? Best kind of fix. :)

Yeah, fortunately I've backported it to Gentoo and managed to notice while we were doing the Python 3.14 testing. Sorry about it and thanks for the quick merge!

@mgorny mgorny deleted the fix-pip-vendor-check branch May 22, 2025 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants