I use AHK in my app, and when I compile the app with pyinstaller and click on the resulting .exe file: this error appears:
Traceback (most recent call last):
File "up.py", line 7, in <module>
File "ahk\keyboard.py", line 94, in key_state
File "ahk\keyboard.py", line 85, in _key_state
File "ahk\script.py", line 130, in render_template
File "jinja2\environment.py", line 1010, in get_template
File "jinja2\environment.py", line 969, in _load_template
File "jinja2\loaders.py", line 126, in load
File "jinja2\loaders.py", line 218, in get_source
jinja2.exceptions.TemplateNotFound: keyboard/key_state.ahk
I copied the templates folder from the autohotkey subdirectory to the project folder, But that doesn't solv my problem. my code:
import time
from ahk import AHK
a=AHK()
press=False
while True:
time.sleep(0.1)
if a.key_state("f11")==True:
press=not press
if press == True:
a.key_press("up")
I was having the same problem and probably everyone who converts to exe will face the same problem --add-data you need to specify, actually that's the reason for the error, here's the code I used for myself, you can edit it
pyinstaller --onefile --noconsole --add-data "C:\Users\fatih\AppData\Local\Programs\Python\Python310\Lib\site-packages\ahk;ahk" mc.py