Skip to content

Commit e1ae5e0

Browse files
authored
cmake: use pip to install tensorflow (#2858)
When setting the `INSTALL_TENSORFLOW` variable, previously CMake calls conda to install tensorflow. Now we use pip to install it. --------- Signed-off-by: Jinzhe Zeng <[email protected]>
1 parent c2c6476 commit e1ae5e0

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

source/CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ if((NOT BUILD_PY_IF) AND (NOT BUILD_CPP_IF))
2525
endif()
2626

2727
if(BUILD_CPP_IF AND BUILD_TESTING)
28-
if(NOT INSTALL_TENSORFLOW)
29-
# some errors in conda packages...
30-
find_package(GTest)
31-
endif()
3228
if(NOT GTEST_LIBRARIES)
3329
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/googletest.cmake.in
3430
googletest-download/CMakeLists.txt @ONLY)
@@ -127,6 +123,9 @@ endif(USE_ROCM_TOOLKIT)
127123
set(DEEPMD_SOURCE_DIR ${PROJECT_SOURCE_DIR}/..)
128124

129125
# setup tensorflow libraries by python
126+
if(INSTALL_TENSORFLOW)
127+
set(USE_TF_PYTHON_LIBS TRUE)
128+
endif(INSTALL_TENSORFLOW)
130129
if(USE_TF_PYTHON_LIBS)
131130
if(NOT "$ENV{CIBUILDWHEEL}" STREQUAL "1")
132131
find_package(

source/cmake/Findtensorflow.cmake

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,30 @@ if(SKBUILD)
1919
endif(SKBUILD)
2020

2121
if(BUILD_CPP_IF AND INSTALL_TENSORFLOW)
22-
# Here we try to install libtensorflow_cc using conda install.
22+
# Here we try to install libtensorflow_cc using pip install.
2323

2424
if(USE_CUDA_TOOLKIT)
25-
set(VARIANT cuda)
25+
set(VARIANT "")
2626
else()
27-
set(VARIANT cpu)
27+
set(VARIANT "-cpu")
2828
endif()
2929

3030
if(NOT DEFINED TENSORFLOW_ROOT)
3131
set(TENSORFLOW_ROOT ${CMAKE_INSTALL_PREFIX})
3232
endif()
33-
# execute conda install
34-
execute_process(COMMAND conda create libtensorflow_cc=*=${VARIANT}* -c
35-
deepmodeling -y -p ${TENSORFLOW_ROOT})
33+
# execute pip install
34+
execute_process(
35+
COMMAND ${Python_EXECUTABLE} -m pip install tensorflow${VARIANT} --no-deps
36+
--target=${TENSORFLOW_ROOT})
37+
set(TENSORFLOW_ROOT
38+
${TENSORFLOW_ROOT}/lib/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages/tensorflow
39+
)
3640
endif()
3741

3842
if(BUILD_CPP_IF
3943
AND USE_TF_PYTHON_LIBS
40-
AND NOT SKBUILD)
44+
AND NOT SKBUILD
45+
AND NOT INSTALL_TENSORFLOW)
4146
# Here we try to install libtensorflow_cc.so as well as
4247
# libtensorflow_framework.so using libs within the python site-package
4348
# tensorflow folder.

0 commit comments

Comments
 (0)