Fail to build debug version on windows

username: teng
cooked: <p>I try to build pytorch from source on Windows, using Anaconda3, and “DEBUG=1”. It failed with fatal error LNK1104 “LNK1104: ╬▐╖¿┤≥┐¬╬─╝■í░python37_d.libí▒”.</p>
<p>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 <a href="http://www.python.org" rel="noopener nofollow ugc">www.python.org</a> 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.</p>
<p>I tried both Visual Studio compiler and Ninja, both failed with the same error.<br>
But it could succeed on Ununtu. Building release version of pytorch on Windows could also succeed.</p>
<p>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?</p>
<p>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)</p>
<blockquote>
<p>pybind_state_dlpack.cc<br>
cl : ??? warning D9025: ???“/W1”(?“/w”) [C:\Users\tegao\mygit\v0512\pytorch\build\caffe2\caffe2_pybind11_state.vcxproj<br>
]<br>
pybind_state_nomni.cc<br>
pybind_state_registry.cc<br>
pybind_state_int8.cc<br>
pybind_state_ideep.cc<br>
LINK : fatal error LNK1104: ╬▐╖¿┤≥┐¬╬─╝■í░python37.libí▒ [C:\Users\tegao\mygit\v0512\pytorch\build\caffe2\caffe2_pybind<br>
11_state.vcxproj]<br>
Building Custom Rule C:/Users/tegao/mygit/v0512/pytorch/third_party/ideep/mkl-dnn/src/CMakeLists.txt<br>
Generating <strong>init</strong>.py<br>
Generating contrib/<strong>init</strong>.py</p>
</blockquote>
<p>Error message when using Ninja:</p>
<blockquote>
<p>[2704/2922] Linking CXX executable bin\extension_backend_test.exe<br>
╒²╘┌┤┤╜¿┐Γ lib\extension_backend_test.lib ║═╢╘╧≤ lib\extension_backend_test.exp<br>
[2706/2922] Linking CXX shared module caffe2\python\caffe2_pybind11_state.cp37-win_amd64.pyd<br>
FAILED: caffe2/python/caffe2_pybind11_state.cp37-win_amd64.pyd<br>
cmd.exe /C “cd . &amp;&amp; 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  &amp;&amp; cd .”<br>
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:<br>
LINK : fatal error LNK1104: ╬▐╖¿┤≥┐¬╬─╝■í░python37.libí▒<br>
[2708/2922] Linking CXX executable bin\pow_test.exe<br>
╒²╘┌┤┤╜¿┐Γ lib\pow_test.lib ║═╢╘╧≤ lib\pow_test.exp<br>
[2709/2922] Building CXX object caffe2\torch\CMakeFiles\torch_python.dir\csrc\jit\backends\backend_init.cpp.obj<br>
ninja: build stopped: subcommand failed.<br>
Traceback (most recent call last):<br>
File “setup.py”, line 740, in <br>
build_deps()<br>
File “setup.py”, line 323, in build_deps<br>
cmake=cmake)<br>
File “C:\Users\tegao\mygit\v0512\pytorch\tools\build_pytorch_libs.py”, line 62, in build_caffe2<br>
cmake.build(my_env)<br>
File “C:\Users\tegao\mygit\v0512\pytorch\tools\setup_helpers\cmake.py”, line 345, in build<br>
self.run(build_args, my_env)<br>
File “C:\Users\tegao\mygit\v0512\pytorch\tools\setup_helpers\cmake.py”, line 141, in run<br>
check_call(command, cwd=self.build_dir, env=env)<br>
File “C:\Users\tegao\Anaconda3\envs\gt37\lib\subprocess.py”, line 363, in check_call<br>
raise CalledProcessError(retcode, cmd)<br>
subprocess.CalledProcessError: Command ‘[‘cmake’, ‘–build’, ‘.’, ‘–target’, ‘install’, ‘–config’, ‘Debug’, ‘–’, ‘-j’, ‘4’]’ returned non-zero exit status 1.</p>
</blockquote>

username: peterjc123
cooked: <p>Actually, you’ll need to append the directory of <code>python37_d.lib</code> to the environment variable <code>LIB</code>. And I vaguely remember that it will then fail with something else that I cannot resolve.</p>

username: teng
cooked: <p>Thank you very much! I works when set LIB.<br>
But after building, it fails to “import torch”. Is it the same problem as yours?</p>
<blockquote>
<p>(gt37) C:\Users\tegao\mygit\v0512\pytorch&gt;python<br>
Python 3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2019, 00:42:30) [MSC v.1916 64 bit (AMD64)] on win32<br>
Type “help”, “copyright”, “credits” or “license” for more information.<br>
&gt;&gt;&gt; import torch<br>
Traceback (most recent call last):<br>
File “”, line 1, in <br>
File “C:\Users\tegao\mygit\v0512\pytorch\torch_<em>init</em>_.py”, line 247, in <br>
from .random import set_rng_state, get_rng_state, manual_seed, initial_seed, seed<br>
File “C:\Users\tegao\mygit\v0512\pytorch\torch\random.py”, line 4, in <br>
from torch._C import default_generator<br>
ImportError: cannot import name ‘default_generator’ from ‘torch._C’ (unknown location)</p>
</blockquote>

username: peterjc123
cooked: <aside class="quote no-group" data-username="teng" data-post="3" data-topic="81127">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/t/b782af/48.png" class="avatar"> teng:</div>
<blockquote>
<p>ImportError: cannot import name ‘default_generator’ from ‘torch._C’ (unknown location)</p>
</blockquote>
</aside>
<p>Nope, mine is a different one. As for your problem, if you have a previous installation, please remember to remove that first.</p>

username: teng
cooked: <p>Thanks a lot!<br>
I move to a new computer and fail to “import torch” again. Because the initial failing to build problem is solved by your kindly help “set LIB=XXX\Anaconda3\envs\myenv\libs”, I close this disscussion and create a new one <a href="https://discuss.pytorch.org/t/fail-to-import-torch-on-windows-debug-build/81347">here</a>.</p>