Skip to content

build: clear venv and skip pip self-upgrade to avoid stale pip corruption - #3360

Merged
kuzeyron merged 1 commit into
kivy:developfrom
Fector101:fix/venv-clear-and-no-pip-upgrade
Jul 30, 2026
Merged

build: clear venv and skip pip self-upgrade to avoid stale pip corruption#3360
kuzeyron merged 1 commit into
kivy:developfrom
Fector101:fix/venv-clear-and-no-pip-upgrade

Conversation

@Fector101

Copy link
Copy Markdown
Contributor

Closes #3339

Problem

run_pymodules_install creates a build venv with python -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 pip replaces files one by one, and if
the process is interrupted mid-upgrade, the old and new files get
interleaved. On re-run, python -m venv venv happily reuses the
existing 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:

  1. --clear flag to python -m venv — wipes the old venv before
    recreating it so stale pip files don't survive between runs.

  2. Removed pip install -U pip — the pip that ships with the host
    Python's ensurepip is perfectly capable of installing Cython and
    pure-Python .whl files. Self-upgrading pip adds risk with zero
    benefit.

Testing

  • tox -e pep8 — passes
  • make test — 460 passed, 2 failed (pre-existing failures in
    test_pythonpackage_basic.py, confirmed against base commit)

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
@kuzeyron
kuzeyron merged commit 0382d27 into kivy:develop Jul 30, 2026
75 of 76 checks passed
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.

run_pymodules_install can reuse stale build/venv and fail with mixed pip/resolvelib state

3 participants