Skip to content

Commit c294e7c

Browse files
authored
[Cmake] Auto detect python in env. (#43)
Signed-off-by: Duyi-Wang <[email protected]>
1 parent dc505cc commit c294e7c

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ target_link_libraries(xfastertransformer
3737
add_dependencies(xfastertransformer_static ${DEPEND_LIST})
3838
add_dependencies(xfastertransformer ${DEPEND_LIST})
3939

40-
execute_process(COMMAND python -m pip show torch
40+
find_package (Python COMPONENTS Interpreter Development)
41+
message(STATUS "Using python: ${Python_EXECUTABLE}")
42+
43+
execute_process(COMMAND ${Python_EXECUTABLE} -m pip show torch
4144
RESULT_VARIABLE EXIT_CODE
4245
OUTPUT_QUIET)
4346
if(${EXIT_CODE} EQUAL 0)

src/pytorch/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ find_package(OpenMP REQUIRED)
1818
find_package(MPI REQUIRED)
1919
find_package(oneCCL REQUIRED)
2020

21-
execute_process(COMMAND python -c "import torch.utils; print(torch.utils.cmake_prefix_path)"
21+
execute_process(COMMAND ${Python_EXECUTABLE} -c "import torch.utils; print(torch.utils.cmake_prefix_path)"
2222
OUTPUT_VARIABLE TORCH_CMAKE_PREFIX_PATH
2323
OUTPUT_STRIP_TRAILING_WHITESPACE)
2424

0 commit comments

Comments
 (0)