ONNX 1.18.0 wheel building fails with Python 3.12: cmake uses system Python instead of runtime Python
#7,226 opened on 2025/08/12
Repository metrics
- Stars
- (16,592 個のスター)
- PR merge metrics
- (平均マージ 1d 23h) (30d で 80 merged PRs)
説明
Problem Description
When building ONNX 1.18.0 wheels in containerized environments, cmake fails because it uses the system Python ( = 3.9.21) instead of the runtime Python version (3.12) that should be used for the build.
Error Message
running build_ext
running cmake_build
Using cmake args: ['/usr/bin/cmake3', '-DPython3_EXECUTABLE=/usr/bin/python3', '-DONNX_BUILD_PYTHON=ON', '-DONNX_NAMESPACE=onnx', '-DCMAKE_BUILD_TYPE=Release', '-DONNX_ML=1', '/work/bootstrap-output/work-dir/onnx-1.18.0/onnx-1.18.0']
-- The C compiler identification is GNU 11.5.0
-- The CXX compiler identification is GNU 11.5.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/lib64/ccache/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/lib64/ccache/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find Python3 (missing: Python3_INCLUDE_DIRS Development.Module)
(found version "3.9.21")
Call Stack (most recent call first):
/usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake/Modules/FindPython/Support.cmake:3766 (find_package_handle_standard_args)
/usr/share/cmake/Modules/FindPython3.cmake:551 (include)
CMakeLists.txt:124 (find_package)
Root Cause
The issue is in setup.py line 173, where the cmake configuration uses:
f"-DPython3_EXECUTABLE={get_python_execute()}",
The get_python_execute() function defaults to the system Python (/usr/bin/python3) rather than the Python interpreter that is actually running the setup script.
Environment
- ONNX Version: 1.18.0
- Container Base: UBI9 (Red Hat Universal Base Image 9)
- System Python: 3.9.21 (
/usr/bin/python3) - Runtime Python: 3.12 (the Python version that should be used for building)
- Build Tool: cmake3
- Context: Containerized wheel building in OpenShift AI/ODH notebook environments
Proposed Solution
Change setup.py line 173 from:
f"-DPython3_EXECUTABLE={get_python_execute()}",
to:
f"-DPython3_EXECUTABLE={sys.executable}",
Justification
sys.executable points to the Python interpreter that is currently running the setup script (the correct runtime Python), while get_python_execute() defaults to the system Python which may be a different version.
This pattern (sys.executable) is widely used in Python build systems and is the standard approach for ensuring cmake uses the same Python version that initiated the build process.
Impact
This affects environments where:
- Multiple Python versions are installed
- The system Python differs from the desired build Python
- Containerized builds where the runtime Python is different from the base system Python
Steps to Reproduce
- Set up a container environment with system Python 3.9 and runtime Python 3.12
- Attempt to build ONNX 1.18.0 wheels using the runtime Python 3.12
- Observe cmake failure due to Python version mismatch
Original Context
This issue was identified in the OpenDataHub notebooks project where ONNX 1.18.0 wheel building fails across all Python 3.12 notebook configurations.
Reference: https://github.com/opendatahub-io/notebooks/issues/1942 Red Hat Jira: https://issues.redhat.com/browse/AIPCC-4265
Reported on behalf of @jiridanek from the OpenDataHub team.