Repository navigation
Description
🐛 Describe the bug
PyTorch fails to import after PyQt on Windows
Description
Importing PyTorch after PyQt on Windows causes a DLL initialization error. The same code works if PyTorch is imported first.
This issue started occurring after upgrading from PyTorch 2.8.0 to 2.9.0.
Reproduction
This code fails:
from PyQt6.QtWidgets import QApplication
import torchResult:
Traceback (most recent call last):
File ""C:\...\abogen\abogen\test.py", line 3, in <module>
import torch
File ""C:\...\Lib\site-packages\torch\__init__.py", line 281, in <module>
_load_dll_libraries()
File ""C:\...\Lib\site-packages\torch\__init__.py", line 264, in _load_dll_libraries
raise err
OSError: [WinError 1114] A dynamic link library (DLL) initialization routine failed. Error loading ""C:\...\Lib\site-packages\torch\lib\c10.dll" or one of its dependencies.This code works:
import torch
from PyQt6.QtWidgets import QApplicationResult:
(imports successfully, no error)
Notes
- Issue started after upgrading from PyTorch
2.8.0to2.9.0. - Affects Windows GUI applications using both PyTorch and PyQt
Note
Issue is still present in PyTorch 2.9.1
Versions
Collecting environment information...
PyTorch version: 2.9.0+cpu
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A
OS: Microsoft Windows 11 Home (10.0.26200 64-bit)
GCC version: Could not collect
Clang version: Could not collect
CMake version: Could not collect
Libc version: N/A
Python version: 3.12.12 [MSC v.1944 64 bit (AMD64)] (64-bit runtime)
Python platform: Windows-11-10.0.26200-SP0
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
Is XPU available: False
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True
Versions of relevant libraries:
[pip3] intel-openmp==2021.4.0
[pip3] mkl==2021.4.0
[pip3] numpy==2.3.4
[pip3] tbb==2021.13.1
[pip3] torch==2.9.0
[pip3] torchaudio==2.9.0
[pip3] torchvision==0.24.0
[conda] Could not collect
cc @seemethere @malfet @atalman @peterjc123 @mszhanyi @skyline75489 @nbcsm @iremyux @Blackhex
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
fteicht commentedon Oct 31, 2025
Hello, I confirm this bug on my side too.
Manoa1911 commentedon Nov 1, 2025
same error here, windows 10 without PyQt, dependency walker shows nothing except api-ms-win missing
RueiHuanRao commentedon Nov 3, 2025
somehow it happens today on my site as well, even thought I solely install pandas and torch using
uv add, and thenimport torchin main.py only.OS: Windows 11
Python Version: 3.12.9
Note: I tried on my Mac, it's totally fine.
denizsafak commentedon Nov 3, 2025
@RueiHuanRao @Manoa1911 @fteicht
There are 4 solutions so far:
Solution 1: Downgrade PyTorch to
2.8.0Solution 2: Pre-load
c10.dllSolution 3: Import torch before PyQt
Solution 4: Install latest Microsoft Visual C++
https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist
isaac-bender commentedon Nov 3, 2025
This also happens with PyQt5.
NelsonGoosman commentedon Nov 4, 2025
Issue persists with PyQt5 + torch 2.9.0. Uninstalling torch and downgrading to 2.8.0 fixed it for me.
RueiHuanRao commentedon Nov 4, 2025
@denizsafak Thank you! I'll have a try!
OnCodeDeny commentedon Nov 5, 2025
Same issue here.
This works:
Even I don't need to import torch in this specific file, pre-importing it before PyQt will make the app run. @denizsafak How did you find out this? Such a weird solution.
denizsafak commentedon Nov 5, 2025
@OnCodeDeny after updating PyTorch, my app started throwing this error. A simple test script that just imported torch worked fine, so I dug deeper and found out the issue was caused by this conflict with PyQt.
aasifdemand commentedon Nov 8, 2025
Same issues with me OSError: [WinError 1114] A dynamic link library (DLL) initialization routine failed. Error loading "C:\Users\Asif Ali\Desktop\Email-Warmup-Tool\app\venv\lib\site-packages\torch\lib\c10.dll" or one of its dependencies
fix: centralize Windows PyTorch DLL pre-loading via advanced library
AmmarMujtaba commentedon Nov 12, 2025
(I think)
I am using PyQt5, and some langchain modules for an AI Agent. Actually, when some packages want the .dll files to execute properly, windows load them in the process's address space. When another package wants the same .dll file, it is not loaded again, and the same pre-loaded file is used for that particular package as well. Torch packages uses newer version of the dll library c10.dll (and probably numerous others as well). But PyQt5 uses the same older vresions. Now, the issue arises when the PyQt5 is placed above the langchain modules, loading the older versions of this .dll in the process's address space. When the control imports the torch module, and tries to use the same older version of that .dll file, it fails to accept that version, and triggers that error.
Placing the PyQt5 module below langchain modules solves the error in the way, that the newer module of the .dll is loaded in the memory, and both the packages agree to use this newer version, solving the issue.
45 remaining items
Fix torch dep
Fix torch dep
Fix torch dep (#576)
infnetdanpro commentedon Sep 9, 2026
Solution 3: Import torch before PyQt - it works!
fix(thelip-server): torch first and pinned to 2.8.0; explain a DLL fa…
tomeeeS commentedon Sep 29, 2026
Note: For those of us who don't use PyQt but have this error: running from terminal - instead of from the IDE (PyCharm) - works for me, and debugging works if I set the "debugpy" debugger mode instead of "pydevd" (the default) in Settings > Python > Debugger. Execution with Run from PyCharm still doesn't work in this way though.
DToxeV commentedon Oct 14, 2026
Same here with PyTorch 2.14.1 + torchvision 0.29.1 (cu126). Importing PyQt5 before YOLO didn’t help. The script runs fine, but the PyInstaller EXE fails with the c10.dll error. Downgrading to torch 2.8.0 + torchvision 0.23.0 (cu126) fixed it (y)
taras-janea commentedon Oct 14, 2026
@DToxeV, have you tried PyTorch 2.15?
taras-janea commentedon Oct 16, 2026
Fixed by #196987