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

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -