Unable to install torchvision

I have download libtorch-debug and libtorch-release, and created and run an example pytorch c++ project. Now I have trouble installing torchvision C++.
What I did:

  1. I compiled and installed pybind11, using cmake --install . and it installed to C:/Program Files(x86)/pybind11 by default.
  2. I tried installing torchvision by first adding set(CMAKE_PREFIX_PATH "path/to/libtorch-release")
    And then:
mkdir build
cd build
cmake ..

And I get the following error:


C:\Users\Peter\Desktop\Programming-Note\PyTorch\vision-master\build>cmake ..
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 6.3.9600.
CMake Warning (dev) at C:/Users/Peter/Desktop/Programming-Note/PyTorch/libtorch-release/share/cmake/Caffe2/public/utils.cmake:81 (if):
  Policy CMP0054 is not set: Only interpret if() arguments as variables or
  keywords when unquoted.  Run "cmake --help-policy CMP0054" for policy
  details.  Use the cmake_policy command to set the policy and suppress this
  warning.

  Quoted variables like "MSVC" will no longer be dereferenced when the policy
  is set to NEW.  Since the policy is not set the OLD behavior will be used.
Call Stack (most recent call first):
  C:/Users/Peter/Desktop/Programming-Note/PyTorch/libtorch-release/share/cmake/Caffe2/Caffe2Config.cmake:121 (caffe2_interface_library)
  C:/Users/Peter/Desktop/Programming-Note/PyTorch/libtorch-release/share/cmake/Torch/TorchConfig.cmake:40 (find_package)

  CMakeLists.txt:14 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at C:/Users/Peter/Desktop/Programming-Note/PyTorch/libtorch-release/share/cmake/Torch/TorchConfig.cmake:108 (if):
  Policy CMP0054 is not set: Only interpret if() arguments as variables or
  keywords when unquoted.  Run "cmake --help-policy CMP0054" for policy
  details.  Use the cmake_policy command to set the policy and suppress this
  warning.

  Quoted variables like "MSVC" will no longer be dereferenced when the policy
  is set to NEW.  Since the policy is not set the OLD behavior will be used.
Call Stack (most recent call first):
  CMakeLists.txt:14 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Error at C:/Users/Peter/Desktop/Programming-Note/PyTorch/pybind11-master/build/pybind11Config.cmake:100 (include):

  include could not find load file:

    pybind11Tools
Call Stack (most recent call first):
  CMakeLists.txt:16 (find_package)


CMake Error at C:/Users/Peter/Desktop/Programming-Note/PyTorch/pybind11-master/build/pybind11Config.cmake:108 (include):

  include could not find load file:

    C:/Users/Peter/Desktop/Programming-Note/PyTorch/pybind11-master/build/pybind11Targets.cmake
Call Stack (most recent call first):
  CMakeLists.txt:16 (find_package)


CMake Error at C:/Users/Peter/Desktop/Programming-Note/PyTorch/pybind11-master/build/pybind11Config.cmake:110 (find_package):
  No "FindPythonLibsNew.cmake" found in CMAKE_MODULE_PATH.
Call Stack (most recent call first):
  CMakeLists.txt:16 (find_package)


CMake Warning (dev) at C:/Users/Peter/Desktop/Programming-Note/PyTorch/pybind11-master/build/pybind11Config.cmake:110 (find_package):
  FindPythonLibsNew.cmake must either be part of this project itself, in this
  case adjust CMAKE_MODULE_PATH so that it points to the correct location
  inside its source tree.

  Or it must be installed by a package which has already been found via
  find_package().  In this case make sure that package has indeed been found
  and adjust CMAKE_MODULE_PATH to contain the location where that package has
  installed FindPythonLibsNew.cmake.  This must be a location provided by
  that package.  This error in general means that the buildsystem of this
  project is relying on a Find-module without ensuring that it is actually
  available.

Call Stack (most recent call first):
  CMakeLists.txt:16 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Configuring incomplete, errors occurred!
See also "C:/Users/Peter/Desktop/Programming-Note/PyTorch/vision-master/build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/Peter/Desktop/Programming-Note/PyTorch/vision-master/build/CMakeFiles/CMakeError.log".

I also tried list(APPEND CMAKE_PREFIX_PATH "path/to/libtorch") list(APPEND CMAKE_PREFIX_PATH "C:/Program Files(x86)/pybind11
doesnot work either.

Pytorch version: LibTorch 1.4 CPU Windows
EDIT: After I delete the pybind source folder, I restart cmake --build torchvision. It compiles but gives an error:

fatal error LNK1104: cannot open file "Torch-NOTFOUND.obj"

Please see Building Torchvision C++ API from source.

I have read that post before, but have no idea how to build it.
I followed the exact process, and use cmake --build . to build torchvision, and I get the link1104 error I mentioned in my post.

cmake --build . --config Release

Thanks for the quick reply, now I get

fatal error LNK1104: cannot open file "python36.lib"

You can try out this patch https://github.com/pytorch/vision/pull/1850.

It seems to build successfully. But when building my project, it generate:

'torch-NOTFOUND', needed by 'example-app.exe`, missing and no known rule to make it.
include could not find load file:
path-to-vision-master/build/TorchVisionTargets.cmake

Likewise, you should select Release over Debug in the VS GUI.

Solved. Visual Studio’s cmake support is buggy. I try to change the CMAKE_BUILD_TYPE in the Visual Studio generated CmakeSettings.json file, and it generates error of the variable has been defined multiple times. I checked the text version of the json file and corrected it manually, and it’s all good now.