ahk
ahk copied to clipboard
How to execute frozen script as exe with PyInstaller? TemplateNotFound
Error while trying to execute script freezed to exe with pyinstaller:
Traceback (most recent call last):
File "autoLogin.py", line 4, in
Hmm. It may be tricky to freeze ahk in its current state. Right now, I build the path to templates folder using __file__ attribute of the script module. When running in a PyInstaller bundle, __file__ is not available at runtime.
Additionally, it would likely be necessary to add the template files to your bundle. See the pyinstaller docs on this.
A possible solution to this would be switching to the Jinja2 package loader, rather than using filesystem loader, which is something I'd like to do for other reasons, but have not quite gotten around to it yet.
Currently made it work by using "pyinstaller --onedir script.py" and then adding "ahk" folder with "templates" folder and also adding "AutoHotkey" folder with "AutoHotkey.exe" to "dist". I specified ahk executable_path as "ahk = AHK(executable_path='.\AutoHotkey\AutoHotkey.exe')"
Hello Timurinyo, I am trying to also compiled a .py script that uses this library and I added the AutoHotKey folder to the project directory but I'm not sure of the templates, when you say 'adding "ahk" folder with "templates", what templates are you referring to specifically and where do I get them? Thank you
Hello gusibis. ahk/templates is lying inside this repo.
I had this exact issue a couple of days ago. The way I solved it was just by adding "--add-data "C:\Program Files\Python37\Lib\site-packages\ahk";ahk"
v1 introduces better compatibility for freezing. There is also a fallback to string constants if templates aren't packaged for any reason.