Skip to content

Commit 1f243cd

Browse files
authored
Better python resolution (pytorch#16389)
### Summary used find_package to resolve python
1 parent 8a2aaa8 commit 1f243cd

1 file changed

Lines changed: 3 additions & 20 deletions

File tree

‎tools/cmake/Utils.cmake‎

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,28 +69,11 @@ function(target_link_options_gc_sections target_name)
6969
endif()
7070
endfunction()
7171

72-
# Sets the value of the PYTHON_EXECUTABLE variable to 'python' if in an active
73-
# (non-base) conda environment, and 'python3' otherwise. This maintains
74-
# backwards compatibility for non-conda users and avoids conda users needing to
75-
# explicitly set PYTHON_EXECUTABLE=python.
7672
function(resolve_python_executable)
77-
# Counter-intuitively, CONDA_DEFAULT_ENV contains the name of the active
78-
# environment.
79-
if(DEFINED ENV{CONDA_DEFAULT_ENV} AND NOT $ENV{CONDA_DEFAULT_ENV} STREQUAL
80-
"base"
81-
)
82-
set(PYTHON_EXECUTABLE
83-
python
84-
PARENT_SCOPE
85-
)
86-
elseif(DEFINED ENV{VIRTUAL_ENV})
87-
set(PYTHON_EXECUTABLE
88-
$ENV{VIRTUAL_ENV}/bin/python3
89-
PARENT_SCOPE
90-
)
91-
else()
73+
if(NOT PYTHON_EXECUTABLE)
74+
find_package(Python3 REQUIRED COMPONENTS Interpreter)
9275
set(PYTHON_EXECUTABLE
93-
python3
76+
${Python3_EXECUTABLE}
9477
PARENT_SCOPE
9578
)
9679
endif()

0 commit comments

Comments
 (0)