Skip to content

PythonInfo.from_exe() reports Python 3.9 for a Python 3.13 executable #124

Description

@dimbleby

On Amazon Linux 2023, PythonInfo.from_exe() resolves a copied Python 3.13 venv to the system-default Python 3.9.

Reproducer

FROM public.ecr.aws/amazonlinux/amazonlinux:2023@sha256:5d271dd33b628252c31c15f5449e50d7c4e9f93badf9342f9b1e2a8d326fbe84

RUN dnf install -y python3.13 python3.13-pip
RUN python3.13 -m venv --copies /venv \
    && /venv/bin/pip install python-discovery==1.4.2

RUN /venv/bin/python - <<'PY'
import subprocess
import sys
from python_discovery import PythonInfo

info = PythonInfo.from_exe(sys.executable)
print(subprocess.check_output([sys.executable, "--version"], text=True).strip())
print(f"{info.executable=}")
print(f"{info.system_executable=}")
print(f"{info.version_info=}")
PY

docker build --no-cache --progress=plain .
Output:

Python 3.13.14
info.executable='/venv/bin/python'
info.system_executable='/usr/bin/python3'
info.version_info=VersionInfo(major=3, minor=9, micro=25, ...)

/usr/bin/python3 points to Python 3.9, while this venv was created from /usr/bin/python3.13.

It appears _fast_get_system_executable() trusts the existing sys._base_executable (/usr/bin/python3) without checking that its version matches the interpreter being inspected. I would expect system_executable to be /usr/bin/python3.13 and version_info to report 3.13.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions