question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pyinstaller & AutoHotkey.exe

See original GitHub issue

Currently, when running a script compiled with Pyinstaller as single file, either Autohotkey itself or ahk-binary pip package needs to be installed. However, if the same .exe is run on a machine lacking either of these, the ahk.script.ExecutableNotFoundError appears, noting that AutoHotkey.exe could not be located.

As known, for Pyinstaller the AHK package data has to be added manually, but doing something like --add-data "C:\Program Files\Python\Lib\site-packages\ahk_binary";ahk_binary still results in the same error. The size of a compiled .exe (using --onefile parameter) does, however, seem to increase by a couple of megabytes – maybe AutoHotkey.exe gets added, but is not found by the AHK part of the script when run.

What is the correct way to include the whole of ahk-binary or at least AutoHotkey.exe (if only that is needed) when compiling with Pyinstaller as single file, so that Autohotkey doesn’t need to be installed on the target machine?

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Poccapxcommented, Dec 5, 2022

And these templates are essential for correct operation? Do agree regarding a cleaner look, but that is also less pedagogical: for someone unfamiliar with how Pyinstaller works, a search for _MEIPASS immediately (literally the first hit) leads to answers of what that line does in the code – not so much for the general __file__. As my issue was solved, you may close this ticket if suitable.

0reactions
spyoungtechcommented, Dec 5, 2022

As I understand it, using __file__ is now supported for apps frozen with pyinstaller, which may be cleaner than _MEIPASS.

what are they for anyway?

The --add-data bit is needed because this project relies on non-python data files (AHK script templates). Under normal conditions, users don’t have to worry about this because the data files are bundled with the package when you install it with pip. However, pyinstaller does not automatically include these files.

I’m thinking about removing the need for that in a future release so pyinstaller integration is less painful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python and AutoHotKey script does not work after compiling to ...
I have a simple AHK script in Python via "ahk 0.12.0" library (pypi). After using pyinstaller to make executable, executable quits giving me ......
Read more >
How to execute frozen script as exe with PyInstaller ... - GitHub
It may be tricky to freeze ahk in its current state. Right now, I build the path to templates folder using __file__ attribute...
Read more >
ahkunwrapped - PyPI
Bundled and bridged AutoHotkey for full native code execution from Python.
Read more >
Retrofit AHK Exe to run any other script : r/AutoHotkey - Reddit
I wonder if it is at all possible to retrofit an AHK-exe ... Just found an awesome new plugin for pyinstaller. pip install...
Read more >
Compiling exe - AutoHotkey Community
However, when I tried to convert the file into an executable, I get this error from AHK, "Ah2Exe.exe /in infile.ahk [/out outfile.exe] ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found