PyTorch compiled from source for Windows is failing when importing torch

  1. Install VS 2017 / 2019 tick C++ desktop development .
  2. Install pyyaml, ninja and numpy pip install pyyaml ninja numpy
  3. Install CMake
  4. Follow the steps in README.md
set DISTUTILS_USE_SDK=1
set REL_WITH_DEB_INFO=1
for /f "usebackq tokens=*" %i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -version [15^,16^) -products * -latest -property installationPath`) do call "%i\VC\Auxiliary\Build\vcvarsall.bat" x64
python setup.py install

Ok, pytorch compiled overnight. Can you please guide me through the next steps?

  1. Launch python from CMD/powershell
  2. Use task manager to find out the PID of that python process.
  3. Open Visual Studio (if 2019, click Continue without code to enter main interface), Debug -> Attach to Process -> (Attach to: Native, in the process list, use pid to find that python.exe) -> Attach
  4. Type in import torch in the CMD/powershell windows and press enter
  5. An exception should be caught in VS, please post the call stack section here.

Import works fine on my build

D:\Dev\pytorch>cd build

D:\Dev\pytorch\build>cd lib.win-amd64-3.7

D:\Dev\pytorch\build\lib.win-amd64-3.7>python
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> print('Torch v{}'.format(torch.__version__))
Torch v1.6.0a0+8a6ab00

It’s weird. Which version of nightly are you using previously?

C:\Windows\System32\locale.nls
C:\Windows\System32\C_1252.NLS
C:\Windows\Globalization\Sorting\SortDefault.nls
C:\Program Files\WindowsApps\Microsoft.LanguageExperiencePackzh-CN_18362.24.76.0_neutral__8wekyb3d8bbwe\Windows\System32\zh-CN\KernelBase.dll.mui
C:\Program Files\WindowsApps\Microsoft.LanguageExperiencePackzh-CN_18362.24.76.0_neutral__8wekyb3d8bbwe\Windows\System32\zh-CN\kernel32.dll.mui
C:\ProgramData\Anaconda3\python.exe
C:\ProgramData\Anaconda3\python37.dll
C:\Windows\System32\pdh.dll
C:\ProgramData\Anaconda3\DLLs_socket.pyd
C:\ProgramData\Anaconda3\Lib\site-packages\psutil_psutil_windows.cp37-win_amd64.pyd
C:\ProgramData\Anaconda3\DLLs\select.pyd
C:\ProgramData\Anaconda3\DLLs_lzma.pyd
C:\ProgramData\Anaconda3\DLLs_bz2.pyd
C:\ProgramData\Anaconda3\vcruntime140.dll
C:\Windows\System32\version.dll
C:\ProgramData\Anaconda3\python3.dll
C:\Windows\System32\wtsapi32.dll
C:\Windows\System32\rsaenh.dll
C:\Windows\System32\IPHLPAPI.DLL
C:\Windows\System32\cryptbase.dll
C:\Windows\System32\winsta.dll
C:\Windows\System32\umpdc.dll
C:\Windows\System32\powrprof.dll
C:\Windows\System32\profapi.dll
C:\Windows\System32\kernel.appcore.dll
C:\Windows\System32\gdi32full.dll
C:\Windows\System32\windows.storage.dll
C:\Windows\System32\cryptsp.dll
C:\Windows\System32\KernelBase.dll
C:\Windows\System32\msvcp_win.dll
C:\Windows\System32\win32u.dll
C:\Windows\System32\bcrypt.dll
C:\Windows\System32\ucrtbase.dll
C:\Windows\System32\cfgmgr32.dll
C:\Windows\System32\bcryptprimitives.dll
C:\Windows\System32\SHCore.dll
C:\Windows\System32\advapi32.dll
C:\Windows\System32\sechost.dll
C:\Windows\System32\msvcrt.dll
C:\Windows\System32\user32.dll
C:\Windows\System32\ws2_32.dll
C:\Windows\System32\rpcrt4.dll
C:\Windows\System32\imm32.dll
C:\Windows\System32\kernel32.dll
C:\Windows\System32\combase.dll
C:\Windows\System32\gdi32.dll
C:\Windows\System32\shell32.dll
C:\Windows\System32\shlwapi.dll
C:\Windows\System32\psapi.dll
C:\Windows\System32\ntdll.dll


Any clue which dll is incompatible or missing?
@peterjc123
Thanks, I’m really an idiot.

You can try the step here to get more details. https://github.com/peterjc123/pytorch_dll_load_smoketests#how-to-contribute-or-report-issues