Fix Python executable detection in virtual environments#7485
Fix Python executable detection in virtual environments#7485
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7485 +/- ##
==========================================
+ Coverage 55.12% 55.25% +0.12%
==========================================
Files 512 513 +1
Lines 32108 32211 +103
Branches 2885 2895 +10
==========================================
+ Hits 17701 17797 +96
- Misses 13618 13620 +2
- Partials 789 794 +5 ☔ View full report in Codecov by Sentry. |
|
@justinchuby @andife please take a look |
|
I think the patch is fine as it is, but I wonder if we should add some tests to check the behavior in general? |
@aoguntayo please look at that comments and if no tests can be provided, please copy/paste a proof of it working for you when building the wheel. Thank you |
|
@EmilienM & @andife |
|
@aoguntayo Could you check the windows test failures and the linting errors? |
The current get_python_execute() function prioritizes a directory-based search over sys.executable, which can incorrectly select the system Python instead of the active runtime Python in virtual environments and containerized builds. This causes build failures when the system Python version differs from the runtime Python version. For example, when building with Python 3.12 in a virtual environment, the function may incorrectly return /usr/bin/python3 (Python 3.9), leading to compatibility issues. Changes: - Check if sys.executable is valid and executable before attempting directory traversal - Only use the include-path-based search as a fallback when sys.executable is invalid - Add docstring explaining the function's behavior - Maintain backward compatibility for the cpython issue #84399 edge case This ensures the build uses the correct Python executable in: - Virtual environments (venv, virtualenv) - Containerized builds - Custom Python installations - Standard system installations Signed-off-by: Anu Oguntayo <aoguntay@redhat.com>
Added a test file to validate the get_python_execute() function Signed-off-by: Anu Oguntayo <aoguntay@redhat.com>
6ef3356 to
49c7f35
Compare
|
@andife Should be okay |
@aoguntayo Have a look at the tests. |
09fe620 to
471b105
Compare
Enable pytest `onnx/test/test_env_python_executable.py` to support windows Signed-off-by: Anu Oguntayo <aoguntay@redhat.com>
471b105 to
1fbe740
Compare
haha sorry for ping pong back and forth XD |

topic: #7226
The current get_python_execute() function prioritizes a directory-based search over sys.executable, which can incorrectly select the system Python instead of the active runtime Python in virtual environments and containerized builds.
This causes build failures when the system Python version differs from the runtime Python version. For example, when building with Python 3.12 in a virtual environment, the function may incorrectly return /usr/bin/python3 (Python 3.9), leading to compatibility issues.
Changes:
This ensures the build uses the correct Python executable in:
Motivation and Context
Fixes #