build: clear venv and skip pip self-upgrade to avoid stale pip corruption - #3360
Merged
kuzeyron merged 1 commit intoJul 30, 2026
Merged
Conversation
Running 'pip install -U pip' during the build occasionally leaves mixed files from two pip versions if the process is interrupted, causing 'ImportError: cannot import name BuildDependencyInstallError' on subsequent runs. Fix by: - Adding '--clear' to venv creation so contaminated state is wiped - Removing the unnecessary pip self-upgrade step entirely
T-Dynamos
approved these changes
Jul 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3339
Problem
run_pymodules_installcreates a build venv withpython -m venv venv.If the build directory already exists from a previous failed run, the
venv can contain a mixed pip installation with files from two different
pip versions —
pip install -U pipreplaces files one by one, and ifthe process is interrupted mid-upgrade, the old and new files get
interleaved. On re-run,
python -m venv venvhappily reuses theexisting directory without cleaning it, so the corrupted state sticks
around permanently.
This showed up as:
ImportError: cannot import name 'BuildDependencyInstallError'
from 'pip._internal.exceptions'
Or, as reported in #3339:
ImportError: cannot import name 'RequirementInformation'
from 'pip._vendor.resolvelib.structs'
Fix
Two changes in
pythonforandroid/build.py:--clearflag topython -m venv— wipes the old venv beforerecreating it so stale pip files don't survive between runs.
Removed
pip install -U pip— the pip that ships with the hostPython's
ensurepipis perfectly capable of installing Cython andpure-Python
.whlfiles. Self-upgrading pip adds risk with zerobenefit.
Testing
tox -e pep8— passesmake test— 460 passed, 2 failed (pre-existing failures intest_pythonpackage_basic.py, confirmed against base commit)