Skip to content

Commit 43cc64b

Browse files
fix: Windows DLL load issues related to PyInstaller (#377)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 931c546 commit 43cc64b

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/ansys/tools/installer/main.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,14 +739,38 @@ def _run_install_python(self, filename):
739739
self.setEnabled(True)
740740

741741

742+
def __restore_windows_dll_load():
743+
"""Restore DLL loading on Windows.
744+
745+
Notes
746+
-----
747+
PyInstaller on Windows may break DLL loading.
748+
This function restores the DLL loading on Windows.
749+
"""
750+
import sys
751+
752+
LOG.debug(f"sys.platform: {sys.platform}")
753+
if sys.platform == "win32":
754+
LOG.debug("Restoring DLL loading on Windows...")
755+
import ctypes
756+
757+
ctypes.windll.kernel32.SetDllDirectoryA(None)
758+
759+
742760
def open_gui():
743761
"""Start the installer as a QT Application."""
744762
import argparse
745763
import ctypes
746764

765+
# Enable logging early
766+
enable_logging()
767+
747768
if os.name == "nt":
748769
import msvcrt
749770

771+
# Restore DLL loading on Windows...
772+
__restore_windows_dll_load()
773+
750774
kernel32 = ctypes.windll.kernel32
751775

752776
# Parse command-line arguments
@@ -776,8 +800,6 @@ def open_gui():
776800
sys.stdout = open("CONOUT$", "w")
777801
sys.stderr = open("CONOUT$", "w")
778802

779-
enable_logging()
780-
781803
app = QtWidgets.QApplication(sys.argv)
782804
window = AnsysPythonInstaller()
783805

0 commit comments

Comments
 (0)