Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Windows DLL load issues related to PyInstaller #377

Merged
merged 5 commits into from
Nov 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/ansys/tools/installer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,14 +739,38 @@ def _run_install_python(self, filename):
self.setEnabled(True)


def __restore_windows_dll_load():
"""Restore DLL loading on Windows.

Notes
-----
PyInstaller on Windows may break DLL loading.
This function restores the DLL loading on Windows.
"""
import sys

LOG.debug(f"sys.platform: {sys.platform}")
if sys.platform == "win32":
LOG.debug("Restoring DLL loading on Windows...")
import ctypes

ctypes.windll.kernel32.SetDllDirectoryA(None)


def open_gui():
"""Start the installer as a QT Application."""
import argparse
import ctypes

# Enable logging early
enable_logging()

if os.name == "nt":
import msvcrt

# Restore DLL loading on Windows...
__restore_windows_dll_load()

kernel32 = ctypes.windll.kernel32

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

enable_logging()

app = QtWidgets.QApplication(sys.argv)
window = AnsysPythonInstaller()

Expand Down
Loading