Skip to content

[WinError 1114] A dynamic link library (DLL) initialization routine failed #166628

Closed

Description

@denizsafak

🐛 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 torch

Result:

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 QApplication

Result:

(imports successfully, no error)

Notes

  • Issue started after upgrading from PyTorch 2.8.0 to 2.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

Activity

  1. added
    module: binariesAnything related to official binaries that we release to users
    triagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module
    on Oct 31, 2025
  2. fteicht commented on Oct 31, 2025

    @fteicht

    Hello, I confirm this bug on my side too.

  3. Manoa1911 commented on Nov 1, 2025

    @Manoa1911

    same error here, windows 10 without PyQt, dependency walker shows nothing except api-ms-win missing

  4. RueiHuanRao commented on Nov 3, 2025

    @RueiHuanRao

    somehow it happens today on my site as well, even thought I solely install pandas and torch using uv add, and then import torch in main.py only.

    OS: Windows 11
    Python Version: 3.12.9

    ...\.venv\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 "...\.venv\Lib\site
    -packages\torch\lib\c10.dll" or one of its dependencies.
    

    Note: I tried on my Mac, it's totally fine.

  5. denizsafak commented on Nov 3, 2025

    @denizsafak
    Author

    @RueiHuanRao @Manoa1911 @fteicht

    There are 4 solutions so far:

    Solution 1: Downgrade PyTorch to 2.8.0

    pip install torch==2.8.0 torchvision==0.23.0 torchaudio==2.8.0

    Solution 2: Pre-load c10.dll

    # Fix PyTorch DLL loading issue on Windows
    # You need to add this at the beginning, before importing torch and other conflicting modules
    
    import os
    import platform
    if platform.system() == "Windows":
        import ctypes
        from importlib.util import find_spec
        try:
            if (spec := find_spec("torch")) and spec.origin and os.path.exists(
                dll_path := os.path.join(os.path.dirname(spec.origin), "lib", "c10.dll")
            ):
                ctypes.CDLL(os.path.normpath(dll_path))
        except Exception:
            pass
    
    # Testing
    from PyQt6.QtWidgets import QApplication
    import torch
    
    # Imports successfully

    Solution 3: Import torch before PyQt

    import torch # imported before PyQt
    from PyQt6.QtWidgets import QApplication

    Solution 4: Install latest Microsoft Visual C++

    https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist

  6. isaac-bender commented on Nov 3, 2025

    @isaac-bender

    This also happens with PyQt5.

  7. NelsonGoosman commented on Nov 4, 2025

    @NelsonGoosman

    Issue persists with PyQt5 + torch 2.9.0. Uninstalling torch and downgrading to 2.8.0 fixed it for me.

  8. RueiHuanRao commented on Nov 4, 2025

    @RueiHuanRao

    @denizsafak Thank you! I'll have a try!

  9. OnCodeDeny commented on Nov 5, 2025

    @OnCodeDeny

    Same issue here.
    This works:

    import torch
    from PyQt6.QtWidgets import QApplication
    

    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.

  10. denizsafak commented on Nov 5, 2025

    @denizsafak
    Author

    @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.

  11. aasifdemand commented on Nov 8, 2025

    @aasifdemand

    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

  12. AmmarMujtaba commented on Nov 12, 2025

    @AmmarMujtaba

    (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.

  13. 45 remaining items

  14. added 2 commits that reference this issue on Aug 17, 2026
  15. added a commit that references this issue on Aug 18, 2026
  16. infnetdanpro commented on Sep 9, 2026

    @infnetdanpro

    Solution 3: Import torch before PyQt - it works!

    • Python 3.13.15
    • torch==2.14.0+cu132
    • torchvision==0.29.0+cu132
  17. tomeeeS commented on Sep 29, 2026

    @tomeeeS

    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.

  18. DToxeV commented on Oct 14, 2026

    @DToxeV

    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)

  19. taras-janea commented on Oct 14, 2026

    @taras-janea
    Collaborator

    @DToxeV, have you tried PyTorch 2.15?

  20. taras-janea commented on Oct 16, 2026

    @taras-janea
    Collaborator

    Fixed by #196987

  21. moved this from In Progress to Done in PyTorch On Windowson Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

module: binariesAnything related to official binaries that we release to usersmodule: windowsWindows support for PyTorchtriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions