I am doing this practice project to implement a LISP interpreter in Python, using help from here. I wanted to create an exe file for the project, executing which would start a REPL. I tried using py2exe and pyInstaller but an error is thrown when I execute the output binary, saying that this script cannot run. Where did I go wrong with my approach and what alternative ways can I use? Thank you.
-
If the script runs normally (invoking *Python* on it), it should run from *py2exe* bundle. You're doing smth wrong. It's also possible embedding *Python*; You could take a look at https://stackoverflow.com/questions/39539089/what-files-are-required-for-py-initialize-to-run, or https://stackoverflow.com/questions/47942845/calling-python-function-with-parametrs-from-c-project-visual-studio, for more details but (both are on *Win*) but that's pretty much what *py2exe* does. – CristiFati Jan 10 '18 at 22:24
1 Answers
It is hard to know for sure but have you checked that all of the required dependencies for your project are either in the same folder as the created executable or (at least) in your path?
The other alternative that I am aware of (and use) is cx_Freeze. This particular exe builder has cross platform support.
cx_Freeze will attempt to automatically find all dependent python modules and include them in the final build. I imagine that the other two options work in the same manner. Packages that cannot be automatically located and binary dependencies (eg dlls, sos) must be explicitly specified in the build configuration scripts.
One method I have for debugging for missing dependencies is to manually copy the suspected missing dependency into the same folder as the .exe to see if it fixes the issue. If it does then I will specify it in the build configuration script.
See https://cx-freeze.readthedocs.io/en/latest/distutils.html for cx_Freeze documentation, in particular section titled build_exe.
Here is a good example of a non-trival setup.py for cx_Freeze: http://www.pythonexample.com/code/cx_freeze-setup/

- 1,255
- 2
- 12
- 26