29 lines
1.2 KiB
Python
29 lines
1.2 KiB
Python
"""
|
|
hook_path.py — PyInstaller runtime hook for Website Checker.
|
|
|
|
Executed by the PyInstaller bootloader before any Python code runs.
|
|
Prepends the bundle's _internal/ directory (where python3xx.dll lives)
|
|
to the Windows PATH so that LoadLibrary() can find the VC++ runtime DLLs
|
|
(vcruntime140.dll, msvcp140.dll, etc.) that python3xx.dll depends on.
|
|
|
|
This resolves the error:
|
|
"Failed to load Python DLL ... python3xx.dll.
|
|
LoadLibrary: The specified module could not be found."
|
|
|
|
Without this hook the DLL is present in the bundle but Windows cannot
|
|
satisfy its own import chain because the VC++ DLLs are not on PATH.
|
|
"""
|
|
import os
|
|
import sys
|
|
|
|
# sys._MEIPASS is set by PyInstaller to the bundle's extraction directory
|
|
# (_internal/ for one-folder builds, a temp dir for --onefile builds).
|
|
try:
|
|
_bundle_dir = sys._MEIPASS
|
|
except AttributeError:
|
|
# Fallback when running outside a PyInstaller bundle (e.g. during testing)
|
|
_bundle_dir = os.path.dirname(os.path.abspath(sys.executable))
|
|
|
|
# Prepend — not append — so the bundle's DLLs take precedence over any
|
|
# system-wide copies that may be an incompatible version.
|
|
os.environ["PATH"] = _bundle_dir + os.pathsep + os.environ.get("PATH", "") |