I try to build pytorch from source on Windows, using Anaconda3, and “DEBUG=1”. It failed with fatal error LNK1104 “LNK1104: ╬▐╖¿┤≥┐¬╬─╝■í░python37_d.libí▒”.
Then I found that “python37_d.lib” didn’t exist on this computer(Anaconda doesn’t have it by default). Then I installed python3.7 from www.python.org 6 and select “Download debug binaries”. Then I copied the whole newly installed python folder to Anaconda3\envs\MyEnv and replace existing old files. When I built pytorch again, it shows “LNK1104: ╬▐╖¿┤≥┐¬╬─╝■í░python37.libí▒”. I checked and made sure both “python37_d.lib” and “python37.lib” are under Anaconda3\envs\MyEnv\libs.
I tried both Visual Studio compiler and Ninja, both failed with the same error.
But it could succeed on Ununtu. Building release version of pytorch on Windows could also succeed.
Is my method wrong(using self-installed python files to replace the ones under Anaconda in order to have pytorch37_d.lib)? How to successfully build debug version of pytorch on windows?
Error message when using Visual Studio compiler: (After failure, I checked the caffe2_pybind11_state.vcxproj and all the path with “python37.lib” and “python37_d.lib” are correct)

pybind_state_dlpack.cc
cl : ??? warning D9025: ???"/W1"(?"/w") [C:\Users\tegao\mygit\v0512\pytorch\build\caffe2\caffe2_pybind11_state.vcxproj
]
pybind_state_nomni.cc
pybind_state_registry.cc
pybind_state_int8.cc
pybind_state_ideep.cc
LINK : fatal error LNK1104: ╬▐╖¿┤≥┐¬╬─╝■í░python37.libí▒ [C:\Users\tegao\mygit\v0512\pytorch\build\caffe2\caffe2_pybind
11_state.vcxproj]
Building Custom Rule C:/Users/tegao/mygit/v0512/pytorch/third_party/ideep/mkl-dnn/src/CMakeLists.txt
Generating init.py
Generating contrib/init.py

Error message when using Ninja:

[2704/2922] Linking CXX executable bin\extension_backend_test.exe
╒²╘┌┤┤╜¿┐Γ lib\extension_backend_test.lib ║═╢╘╧≤ lib\extension_backend_test.exp
[2706/2922] Linking CXX shared module caffe2\python\caffe2_pybind11_state.cp37-win_amd64.pyd
FAILED: caffe2/python/caffe2_pybind11_state.cp37-win_amd64.pyd
cmd.exe /C “cd . && C:\Users\tegao\Anaconda3\envs\gt37\Library\bin\cmake.exe -E vs_link_dll --intdir=caffe2\CMakeFiles\caffe2_pybind11_state.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100177~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100177~1.0\x64\mt.exe --manifests  – C:\PROGRA~2\MIB055~1\2017\PROFES~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\x64\link.exe /nologo caffe2\CMakeFiles\caffe2_pybind11_state.dir\python\pybind_state.cc.obj caffe2\CMakeFiles\caffe2_pybind11_state.dir\python\pybind_state_dlpack.cc.obj caffe2\CMakeFiles\caffe2_pybind11_state.dir\python\pybind_state_nomni.cc.obj caffe2\CMakeFiles\caffe2_pybind11_state.dir\python\pybind_state_registry.cc.obj caffe2\CMakeFiles\caffe2_pybind11_state.dir\python\pybind_state_int8.cc.obj caffe2\CMakeFiles\caffe2_pybind11_state.dir\python\pybind_state_ideep.cc.obj  /out:caffe2\python\caffe2_pybind11_state.cp37-win_amd64.pyd /implib:lib\caffe2_pybind11_state.lib /pdb:caffe2\python\caffe2_pybind11_state.pdb /dll /version:0.0 /machine:x64 /ignore:4049 /ignore:4217 /debug /INCREMENTAL:NO /machine:x64 /ignore:4049 /ignore:4217  C:\Users\tegao\Anaconda3\envs\gt37\libs\python37_d.lib  lib\onnx_proto.lib  lib\torch.lib  lib\torch_cpu.lib  lib\c10.lib  lib\dnnl.lib  lib\libprotobufd.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib  && cd .”
LINK: command “C:\PROGRA~2\MIB055~1\2017\PROFES~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\x64\link.exe /nologo caffe2\CMakeFiles\caffe2_pybind11_state.dir\python\pybind_state.cc.obj caffe2\CMakeFiles\caffe2_pybind11_state.dir\python\pybind_state_dlpack.cc.obj caffe2\CMakeFiles\caffe2_pybind11_state.dir\python\pybind_state_nomni.cc.obj caffe2\CMakeFiles\caffe2_pybind11_state.dir\python\pybind_state_registry.cc.obj caffe2\CMakeFiles\caffe2_pybind11_state.dir\python\pybind_state_int8.cc.obj caffe2\CMakeFiles\caffe2_pybind11_state.dir\python\pybind_state_ideep.cc.obj /out:caffe2\python\caffe2_pybind11_state.cp37-win_amd64.pyd /implib:lib\caffe2_pybind11_state.lib /pdb:caffe2\python\caffe2_pybind11_state.pdb /dll /version:0.0 /machine:x64 /ignore:4049 /ignore:4217 /debug /INCREMENTAL:NO /machine:x64 /ignore:4049 /ignore:4217 C:\Users\tegao\Anaconda3\envs\gt37\libs\python37_d.lib lib\onnx_proto.lib lib\torch.lib lib\torch_cpu.lib lib\c10.lib lib\dnnl.lib lib\libprotobufd.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:caffe2\python\caffe2_pybind11_state.cp37-win_amd64.pyd.manifest” failed (exit code 1104) with the following output:
LINK : fatal error LNK1104: ╬▐╖¿┤≥┐¬╬─╝■í░python37.libí▒
[2708/2922] Linking CXX executable bin\pow_test.exe
╒²╘┌┤┤╜¿┐Γ lib\pow_test.lib ║═╢╘╧≤ lib\pow_test.exp
[2709/2922] Building CXX object caffe2\torch\CMakeFiles\torch_python.dir\csrc\jit\backends\backend_init.cpp.obj
ninja: build stopped: subcommand failed.
Traceback (most recent call last):
File “setup.py”, line 740, in 
build_deps()
File “setup.py”, line 323, in build_deps
cmake=cmake)
File “C:\Users\tegao\mygit\v0512\pytorch\tools\build_pytorch_libs.py”, line 62, in build_caffe2
cmake.build(my_env)
File “C:\Users\tegao\mygit\v0512\pytorch\tools\setup_helpers\cmake.py”, line 345, in build
self.run(build_args, my_env)
File “C:\Users\tegao\mygit\v0512\pytorch\tools\setup_helpers\cmake.py”, line 141, in run
check_call(command, cwd=self.build_dir, env=env)
File “C:\Users\tegao\Anaconda3\envs\gt37\lib\subprocess.py”, line 363, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command ‘[‘cmake’, ‘–build’, ‘.’, ‘–target’, ‘install’, ‘–config’, ‘Debug’, ‘–’, ‘-j’, ‘4’]’ returned non-zero exit status 1.