Unable to install torchvision

sz_ppeter: <p>I have download <code>libtorch-debug</code> and <code>libtorch-release</code>, and created and run an example pytorch c++ project. Now I have trouble installing torchvision C++.<br>
What I did:</p>
<ol>
<li>I compiled and installed pybind11, using <code>cmake --install .</code> and it installed to <code>C:/Program Files(x86)/pybind11</code> by default.</li>
<li>I tried installing torchvision by first adding <code>set(CMAKE_PREFIX_PATH "path/to/libtorch-release")</code><br>
And then:</li>
</ol>
<pre><code class="lang-auto">mkdir build
cd build
cmake ..
</code></pre>
<p>And I get the following error:</p>
<pre><code class="lang-auto">
C:\Users\Peter\Desktop\Programming-Note\PyTorch\vision-master\build&gt;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".
</code></pre>
<p>I also tried <code>list(APPEND CMAKE_PREFIX_PATH "path/to/libtorch") list(APPEND CMAKE_PREFIX_PATH "C:/Program Files(x86)/pybind11</code><br>
doesnot work either.</p>
<p>Pytorch version: LibTorch 1.4 CPU Windows<br>
EDIT: After I delete the pybind source folder, I restart <code>cmake --build</code> torchvision. It compiles but gives an error:</p>
<pre><code class="lang-auto">fatal error LNK1104: cannot open file "Torch-NOTFOUND.obj"
</code></pre>

peterjc123: <p>Please see <a href="https://discuss.pytorch.org/t/building-torchvision-c-api-from-source/68281/2" class="inline-onebox">Building Torchvision C++ API from source</a>.</p>

sz_ppeter: <p>I have read that post before, but have no idea how to build it.<br>
I followed the exact process, and use <code>cmake --build .</code> to build torchvision, and I get the link1104 error I mentioned in my post.</p>

peterjc123: <p><code>cmake --build . --config Release</code></p>

sz_ppeter: <p>Thanks for the quick reply, now I get</p>
<pre><code class="lang-auto">fatal error LNK1104: cannot open file "python36.lib"
</code></pre>

peterjc123: <p>You can try out this patch <a href="https://github.com/pytorch/vision/pull/1850" rel="nofollow noopener">https://github.com/pytorch/vision/pull/1850</a>.</p>

sz_ppeter: <p>It seems to build successfully. But when building my project, it generate:</p>
<pre><code class="lang-auto">'torch-NOTFOUND', needed by 'example-app.exe`, missing and no known rule to make it.
</code></pre>
<pre><code class="lang-auto">include could not find load file:
path-to-vision-master/build/TorchVisionTargets.cmake
</code></pre>

peterjc123: <p>Likewise, you should select Release over Debug in the VS GUI.</p>

sz_ppeter: <p>Solved. Visual Studio’s cmake support is buggy. I try to change the <code>CMAKE_BUILD_TYPE</code> in the Visual Studio generated <code>CmakeSettings.json</code> 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.</p>