I have a python script, distributed across several files, all within a single directory. I would like to distribute this as a single executable file (for linux systems, mainly), such that the file can be moved around and copied easily.
I've come as far as renaming my main file to __main__.py
, and zipping everything into myscript.zip
, so now I can run python myscript.zip
. But that's one step too short. I want to run this as ./myscript
, without creating an alias or a wrapper script.
Is this possible at all? What's the best way? I thought that maybe the zip file could be embedded in a (ba)sh script, that passes it to python (but without creating a temporary file, if possible).
EDIT:
After having another go at setuptools
(I had not managed to make it work before), I could create sort of self-contained script, an "eggsecutable script". The trick is that in this case you cannot have your main module named __main__.py
. Then there are still a couple of issues: the resulting script cannot be renamed and it still creates the __pycache__
directory when run. I solved these by modifying the shell-script code at the beginning of the file, and adding the -B
flag to the python command there.
EDIT (2): Not that easy either, it was working because I still had my source .py
files next to the "eggsecutable", move something and it stops working.