[Solved] Problem with cmake when building from source in Windows7

Hello everyone,

I am trying to build pytorch from source in order to use CUDA with my old 780m graphic card following the instructions found at : https://github.com/pytorch/pytorch#from-source

I am encountering the following problem when I try to run the

python setup.py install

command. The output (in anaconda prompt) is:

(base) C:\WINDOWS\System32\pytorch>python setup.py install
Building wheel torch-1.2.0a0+8dbdd00
-- Building version 1.2.0a0+8dbdd00
['cmake',
 '-GNinja',
 '-DMSVC_Z7_OVERRIDE=ON',
 '-DBUILDING_WITH_TORCH_LIBS=ON',
 '-DBUILD_BINARY=False',
 '-DBUILD_CAFFE2_OPS=True',
 '-DBUILD_PYTHON=True',
 '-DBUILD_SHARED_LIBS=ON',
 '-DBUILD_TEST=True',
 '-DCAFFE2_STATIC_LINK_CUDA=False',
 '-DCMAKE_BUILD_TYPE=Release',
 '-DCMAKE_CXX_FLAGS=  /EHa',
 '-DCMAKE_C_FLAGS=  /EHa',
 '-DCMAKE_EXE_LINKER_FLAGS=',
 '-DCMAKE_INSTALL_PREFIX=C:\\WINDOWS\\System32\\pytorch/torch',
 '-DCMAKE_PREFIX_PATH=C:\\ProgramData\\Anaconda3\\Lib\\site-packages',
 '-DCMAKE_SHARED_LINKER_FLAGS=',
 '-DCMAKE_VERBOSE_MAKEFILE=ON',
 '-DINSTALL_TEST=True',
 '-DNAMEDTENSOR_ENABLED=False',
 '-DNCCL_EXTERNAL=False',
 '-DNUMPY_INCLUDE_DIR=C:/ProgramData/Anaconda3/lib/site-packages/numpy/core/incl
ude',
 '-DONNX_ML=False',
 '-DONNX_NAMESPACE=onnx_torch',
 '-DPYTHON_EXECUTABLE=C:/ProgramData/Anaconda3/python.exe',
 '-DPYTHON_INCLUDE_DIR=C:/ProgramData/Anaconda3/include',
 '-DPYTHON_LIBRARY=C:/ProgramData/Anaconda3/libs/python37.lib',
 '-DTHD_SO_VERSION=1',
 '-DTORCH_BUILD_VERSION=1.2.0a0+8dbdd00',
 '-DUSE_ASAN=False',
 '-DUSE_CUDA=True',
 '-DUSE_DISTRIBUTED=False',
 '-DUSE_FBGEMM=True',
 '-DUSE_FFMPEG=False',
 '-DUSE_LEVELDB=False',
 '-DUSE_LMDB=False',
 '-DUSE_MKLDNN=True',
 '-DUSE_NCCL=False',
 '-DUSE_NNPACK=True',
 '-DUSE_NUMPY=True',
 '-DUSE_OPENCV=False',
 '-DUSE_QNNPACK=True',
 '-DUSE_ROCM=False',
 '-DUSE_SYSTEM_EIGEN_INSTALL=OFF',
 '-DUSE_SYSTEM_NCCL=False',
 '-DUSE_TENSORRT=False',
 '-DMKLDNN_ENABLE_CONCURRENT_EXEC=ON',
 'C:\\WINDOWS\\System32\\pytorch']
-- The CXX compiler identification is MSVC 19.11.25548.2
-- The C compiler identification is MSVC 19.11.25548.2
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studi
o/2017/Community/VC/Tools/MSVC/14.11.25503/bin/HostX64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studi
o/2017/Community/VC/Tools/MSVC/14.11.25503/bin/HostX64/x64/cl.exe -- broken
CMake Error at C:/ProgramData/Anaconda3/Library/share/cmake-3.14/Modules/CMakeTe
stCXXCompiler.cmake:53 (message):
  The C++ compiler

    "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC
/14.11.25503/bin/HostX64/x64/cl.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: C:/WINDOWS/System32/pytorch/build/CMakeFiles/CMakeTmp

    Run Build Command(s):C:/ProgramData/Anaconda3/Library/bin/ninja.exe cmTC_5bf
22
    [1/2] Building CXX object CMakeFiles\cmTC_5bf22.dir\testCXXCompiler.cxx.obj
    [2/2] Linking CXX executable cmTC_5bf22.exe
    FAILED: cmTC_5bf22.exe
    cmd.exe /C "cd . && C:\ProgramData\Anaconda3\Library\bin\cmake.exe -E vs_lin
k_exe --intdir=CMakeFiles\cmTC_5bf22.dir --rc=rc --mt=CMAKE_MT-NOTFOUND --manife
sts  -- C:\PROGRA~2\MIB055~1\2017\COMMUN~1\VC\Tools\MSVC\1411~1.255\bin\HostX64\
x64\link.exe /nologo CMakeFiles\cmTC_5bf22.dir\testCXXCompiler.cxx.obj  /out:cmT
C_5bf22.exe /implib:cmTC_5bf22.lib /pdb:cmTC_5bf22.pdb /version:0.0  /debug /INC
REMENTAL /subsystem:console  kernel32.lib user32.lib gdi32.lib winspool.lib shel
l32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
    RC Pass 1: command "rc /foCMakeFiles\cmTC_5bf22.dir/manifest.res CMakeFiles\
cmTC_5bf22.dir/manifest.rc" failed (exit code 0) with the following output:
    Le fichier spécifié est introuvable
    ninja: build stopped: subcommand failed.




  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:11 (project)


-- Configuring incomplete, errors occurred!
See also "C:/WINDOWS/System32/pytorch/build/CMakeFiles/CMakeOutput.log".
See also "C:/WINDOWS/System32/pytorch/build/CMakeFiles/CMakeError.log".
Traceback (most recent call last):
  File "setup.py", line 734, in <module>
    build_deps()
  File "setup.py", line 299, in build_deps
    build_dir='build')
  File "C:\WINDOWS\System32\pytorch\tools\build_pytorch_libs.py", line 281, in b
uild_caffe2
    my_env)
  File "C:\WINDOWS\System32\pytorch\tools\build_pytorch_libs.py", line 261, in r
un_cmake
    check_call(cmake_args, cwd=build_dir, env=my_env)
  File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 347, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '-GNinja', '-DMSVC_Z7_OVERRIDE
=ON', '-DBUILDING_WITH_TORCH_LIBS=ON', '-DBUILD_BINARY=False', '-DBUILD_CAFFE2_O
PS=True', '-DBUILD_PYTHON=True', '-DBUILD_SHARED_LIBS=ON', '-DBUILD_TEST=True',
'-DCAFFE2_STATIC_LINK_CUDA=False', '-DCMAKE_BUILD_TYPE=Release', '-DCMAKE_CXX_FL
AGS=  /EHa', '-DCMAKE_C_FLAGS=  /EHa', '-DCMAKE_EXE_LINKER_FLAGS=', '-DCMAKE_INS
TALL_PREFIX=C:\\WINDOWS\\System32\\pytorch/torch', '-DCMAKE_PREFIX_PATH=C:\\Prog
ramData\\Anaconda3\\Lib\\site-packages', '-DCMAKE_SHARED_LINKER_FLAGS=', '-DCMAK
E_VERBOSE_MAKEFILE=ON', '-DINSTALL_TEST=True', '-DNAMEDTENSOR_ENABLED=False', '-
DNCCL_EXTERNAL=False', '-DNUMPY_INCLUDE_DIR=C:/ProgramData/Anaconda3/lib/site-pa
ckages/numpy/core/include', '-DONNX_ML=False', '-DONNX_NAMESPACE=onnx_torch', '-
DPYTHON_EXECUTABLE=C:/ProgramData/Anaconda3/python.exe', '-DPYTHON_INCLUDE_DIR=C
:/ProgramData/Anaconda3/include', '-DPYTHON_LIBRARY=C:/ProgramData/Anaconda3/lib
s/python37.lib', '-DTHD_SO_VERSION=1', '-DTORCH_BUILD_VERSION=1.2.0a0+8dbdd00',
'-DUSE_ASAN=False', '-DUSE_CUDA=True', '-DUSE_DISTRIBUTED=False', '-DUSE_FBGEMM=
True', '-DUSE_FFMPEG=False', '-DUSE_LEVELDB=False', '-DUSE_LMDB=False', '-DUSE_M
KLDNN=True', '-DUSE_NCCL=False', '-DUSE_NNPACK=True', '-DUSE_NUMPY=True', '-DUSE
_OPENCV=False', '-DUSE_QNNPACK=True', '-DUSE_ROCM=False', '-DUSE_SYSTEM_EIGEN_IN
STALL=OFF', '-DUSE_SYSTEM_NCCL=False', '-DUSE_TENSORRT=False', '-DMKLDNN_ENABLE_
CONCURRENT_EXEC=ON', 'C:\\WINDOWS\\System32\\pytorch']' returned non-zero exit s
tatus 1.

Would you know how to alleviate this problem please ?

Thanks!

[Solved] : this was a problem with Visual Studio installation. The solution was to install the C++ desktop workload from the VS installer > modify > workloads.