Distributing set of python files as a single executable -
i have python script, distributed across several files, within single directory. distribute single executable file (for linux systems, mainly), such file can moved around , copied easily.
i've come far renaming main file __main__.py
, , zipping myscript.zip
, can run python myscript.zip
. that's 1 step short. want run ./myscript
, without creating alias or wrapper script.
is possible @ all? what's best way? thought maybe zip file embedded in (ba)sh script, passes python (but without creating temporary file, if possible).
edit: after having go @ setuptools
(i had not managed make work before), create sort of self-contained script, "eggsecutable script". trick in case cannot have main module named __main__.py
. there still couple of issues: resulting script cannot renamed , still creates __pycache__
directory when run. solved these modifying shell-script code @ beginning of file, , adding -b
flag python command there.
edit (2): not easy either, working because still had source .py
files next "eggsecutable", move , stops working.
you can edit raw zip file binary , insert shebang first line.
#!/usr/bin/env python pk...rest of zip
of course need appropriate editor this, can handle binary files (e.g.: vim -b
) or can make small bash script.
{ echo '#!/usr/bin/env python'; cat myscript.zip; } > myscript chmod +x myscript ./myscript
Comments
Post a Comment