@@ -837,76 +837,43 @@ include_directories(SYSTEM ${EIGEN3_INCLUDE_DIR})
837
837
# ---[ Python + Numpy
838
838
if (BUILD_PYTHON)
839
839
# If not given a Python installation, then use the current active Python
840
- if (NOT PYTHON_EXECUTABLE )
840
+ if (NOT Python_EXECUTABLE )
841
841
execute_process (
842
- COMMAND "which" "python " RESULT_VARIABLE _exitcode OUTPUT_VARIABLE _py_exe)
842
+ COMMAND "which" "python3 " RESULT_VARIABLE _exitcode OUTPUT_VARIABLE _py_exe)
843
843
if (${_exitcode} EQUAL 0)
844
844
if (NOT MSVC )
845
- string (STRIP ${_py_exe} PYTHON_EXECUTABLE )
845
+ string (STRIP ${_py_exe} Python_EXECUTABLE )
846
846
endif ()
847
- message (STATUS "Setting Python to ${PYTHON_EXECUTABLE } " )
847
+ message (STATUS "Setting Python to ${Python_EXECUTABLE } " )
848
848
endif ()
849
849
endif ()
850
850
851
851
# Check that Python works
852
852
set (PYTHON_VERSION)
853
- if (DEFINED PYTHON_EXECUTABLE )
853
+ if (DEFINED Python_EXECUTABLE )
854
854
execute_process (
855
- COMMAND "${PYTHON_EXECUTABLE } " "--version"
855
+ COMMAND "${Python_EXECUTABLE } " "--version"
856
856
RESULT_VARIABLE _exitcode OUTPUT_VARIABLE PYTHON_VERSION)
857
857
if (NOT _exitcode EQUAL 0)
858
- message (FATAL_ERROR "The Python executable ${PYTHON_EXECUTABLE } cannot be run. Make sure that it is an absolute path." )
858
+ message (FATAL_ERROR "The Python executable ${Python_EXECUTABLE } cannot be run. Make sure that it is an absolute path." )
859
859
endif ()
860
860
if (PYTHON_VERSION)
861
861
string (REGEX MATCH "([0-9]+)\\ .([0-9]+)" PYTHON_VERSION ${PYTHON_VERSION} )
862
862
endif ()
863
863
endif ()
864
864
865
- # Seed PYTHON_INCLUDE_DIR and PYTHON_LIBRARY to be consistent with the
866
- # executable that we already found (if we didn't actually find an executable
867
- # then these will just use "python", but at least they'll be consistent with
868
- # each other).
869
- if (NOT PYTHON_INCLUDE_DIR)
870
- # TODO: Verify that sysconfig isn't inaccurate
871
- pycmd_no_exit(_py_inc _exitcode "import sysconfig; print(sysconfig.get_path('include'))" )
872
- if ("${_exitcode} " EQUAL 0 AND IS_DIRECTORY "${_py_inc} " )
873
- set (PYTHON_INCLUDE_DIR "${_py_inc} " )
874
- message (STATUS "Setting Python's include dir to ${_py_inc} from sysconfig" )
875
- else ()
876
- message (WARNING "Could not set Python's include dir to ${_py_inc} from sysconfig" )
877
- endif ()
878
- endif (NOT PYTHON_INCLUDE_DIR)
879
-
880
- if (NOT PYTHON_LIBRARY)
881
- pycmd_no_exit(_py_lib _exitcode "import sysconfig; print(sysconfig.get_path('stdlib'))" )
882
- if ("${_exitcode} " EQUAL 0 AND EXISTS "${_py_lib} " AND EXISTS "${_py_lib} " )
883
- set (PYTHON_LIBRARY "${_py_lib} " )
884
- if (MSVC )
885
- string (REPLACE "Lib" "libs" _py_static_lib ${_py_lib} )
886
- link_directories (${_py_static_lib} )
887
- endif ()
888
- message (STATUS "Setting Python's library to ${PYTHON_LIBRARY} " )
889
- endif ()
890
- endif (NOT PYTHON_LIBRARY)
891
-
892
865
# These should fill in the rest of the variables, like versions, but resepct
893
866
# the variables we set above
894
- set (Python_ADDITIONAL_VERSIONS ${PYTHON_VERSION} 3.8)
895
- find_package (PythonInterp 3.0)
896
- find_package (PythonLibs 3.0)
867
+ find_package (Python COMPONENTS Interpreter Development)
897
868
898
- if (NOT PYTHONLIBS_VERSION_STRING )
869
+ if (NOT Python_Development_FOUND )
899
870
message (FATAL_ERROR
900
871
"Python development libraries could not be found." )
901
872
endif ()
902
873
903
- if (${PYTHONLIBS_VERSION_STRING} VERSION_LESS 3)
904
- message (FATAL_ERROR
905
- "Found Python libraries version ${PYTHONLIBS_VERSION_STRING} . Python 2 has reached end-of-life and is no longer supported by PyTorch." )
906
- endif ()
907
- if (${PYTHONLIBS_VERSION_STRING} VERSION_LESS 3.8)
874
+ if (${Python_VERSION} VERSION_LESS 3.8)
908
875
message (FATAL_ERROR
909
- "Found Python libraries version ${PYTHONLIBS_VERSION_STRING } . Python < 3.8 is no longer supported by PyTorch." )
876
+ "Found Python libraries version ${Python_VERSION } . Python < 3.8 is no longer supported by PyTorch." )
910
877
endif ()
911
878
912
879
# When building pytorch, we pass this in directly from setup.py, and
@@ -920,11 +887,11 @@ if(BUILD_PYTHON)
920
887
endif ()
921
888
endif ()
922
889
923
- if (PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND )
890
+ if (Python_Interpreter_FOUND AND Python_Development_FOUND )
924
891
add_library (python::python INTERFACE IMPORTED )
925
- target_include_directories (python::python SYSTEM INTERFACE ${PYTHON_INCLUDE_DIRS } )
892
+ target_include_directories (python::python SYSTEM INTERFACE ${Python_INCLUDE_DIRS } )
926
893
if (WIN32 )
927
- target_link_libraries (python::python INTERFACE ${PYTHON_LIBRARIES } )
894
+ target_link_libraries (python::python INTERFACE ${Python_LIBRARIES } )
928
895
endif ()
929
896
930
897
caffe2_update_option(USE_NUMPY OFF )
@@ -960,10 +927,7 @@ endif()
960
927
message (STATUS "pybind11 include dirs: " "${pybind11_INCLUDE_DIRS} " )
961
928
add_library (pybind::pybind11 INTERFACE IMPORTED )
962
929
target_include_directories (pybind::pybind11 SYSTEM INTERFACE ${pybind11_INCLUDE_DIRS} )
963
- target_link_libraries (pybind::pybind11 INTERFACE python::python)
964
- if (APPLE )
965
- target_link_options (pybind::pybind11 INTERFACE -undefined dynamic_lookup)
966
- endif ()
930
+ target_link_libraries (pybind::pybind11 INTERFACE Python::Module)
967
931
968
932
# ---[ OpenTelemetry API headers
969
933
find_package (OpenTelemetryApi)
0 commit comments