One of common question of python programming is how to do jar equivalent - i.e. run something like python myapp.zip . Below I describe a method producing a close result (hey python team - good place to enhance): unfortunately couple of bugs in python zip handling (e.g. python can't import module from zipfile with comments) make this task a little bit tricky.
- Make sure you app is ready to work with zip bundle i.e. file is replaced to ZipFile when necessary.
- Prepare the entry point:
main.py def __main__(): ....
- create a bundle
zip -r test.zip *.py *.pyc
- create a launcher either shell or pure python one and place it somewhere.
#!/bin/sh mod="$1" shift python -c "import sys; sys.path.insert(0,'${mod}'); import main;main.__main__()" $*import sys sys.path.insert(0,sys.argv[1]) import main main.__main__()enjoy