Skip to content

fix(doctor): use sys.executable for pip show in _pip_version#2

Merged
moonandlife merged 1 commit into
mainfrom
ws/fix-doctor-pip-version-sys-executable
Jun 10, 2026
Merged

fix(doctor): use sys.executable for pip show in _pip_version#2
moonandlife merged 1 commit into
mainfrom
ws/fix-doctor-pip-version-sys-executable

Conversation

@moonandlife

Copy link
Copy Markdown
Contributor

Summary

Fix hust-ascend-manager setup / doctor failing on minimal Ascend
runtimes where the conda env only exposes python3 (not python).

Root cause

In src/hust_ascend_manager/doctor.py, _pip_version was hardcoding
the interpreter name:

def _pip_version(pkg: str) -> str | None:
    rc, out, _ = _run(["python", "-m", "pip", "show", pkg])

On runners where the active env ships only python3 (typical of
Euleros/Ascend base images and minimal CI runners), this raises:

FileNotFoundError: [Errno 2] No such file or directory: 'python'

The traceback was observed in CI when setup invokes
doctor.collect_report() (see cli.py:140setup.py:220
doctor.py:703_pip_version).

Fix

Replace the hardcoded "python" with sys.executable. This is
guaranteed to:

  • be the actual interpreter that imported the manager (so it always
    exists as a real path)
  • have pip available in the same env
  • be the right interpreter for conda envs, venvs, and containers,
    regardless of whether python, python3, or python3.11 is in
    PATH

No new imports needed (sys is already imported at the top of
doctor.py).

Scope

Single-line change in _pip_version. Sibling module runtime.py
already handles the same concern with an explicit
("python3", "python") fallback list — sys.executable is the
more robust version of that pattern.

Verification

  • pytest tests/ -q: 66 passed (no test changes needed — they mock
    _pip_version directly).
  • _pip_version("pip") returns the actual version
    ('26.1.2' in the dev env).
  • _pip_version("not-a-real-pkg") returns None (unchanged
    behaviour on missing packages).

Related

This is the same class of issue that already exists in
runtime.py:38 (for candidate in ("python3", "python")), but
the doctor path was missed. This PR only fixes the doctor path. The
runtime path can be unified with sys.executable in a follow-up
if desired.

Assisted-by: Qoder Agent

The 'doctor' command failed on runners where the conda environment
only exposes 'python3' (not 'python') in PATH:

  File '.../hust_ascend_manager/doctor.py', line 295, in _pip_version
    rc, out, _ = _run(['python', '-m', 'pip', 'show', pkg])
  FileNotFoundError: [Errno 2] No such file or directory: 'python'

This blocks 'hust-ascend-manager setup' (which calls doctor.collect_report)
on minimal Ascend images and CI runners. Hardcoding 'python' is fragile:
on Euleros / Ascend base images the venv only ships python3 binaries.

Fix: invoke the same Python interpreter that is running the manager
itself, via sys.executable. This is guaranteed to:
- exist (it is the running process)
- have pip available (we loaded from this env)
- be the canonical interpreter for the active env, regardless of
  whether the user has 'python', 'python3', 'python3.11', etc. in PATH
- work inside conda envs, venvs, and containers without modification

No new imports needed: 'sys' is already imported at the top of
doctor.py. Sibling module 'runtime.py' already handles this concern
with an explicit ('python3', 'python') fallback list (line 38); using
sys.executable is more robust because it is the actual interpreter
that imported the package.

Verification:
- pytest tests/ -q: 66 passed
- _pip_version('pip') returns the expected version
- _pip_version('not-a-real-package') returns None (same as before)

Co-authored-by: Qoder Agent
@moonandlife moonandlife merged commit be99427 into main Jun 10, 2026
1 check passed
@moonandlife moonandlife deleted the ws/fix-doctor-pip-version-sys-executable branch June 10, 2026 08:35
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.

1 participant