Skip to content

Instantly share code, notes, and snippets.

@reimai
Created July 29, 2016 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reimai/6ba8b1139a6f64caf0b53e4fb470bfba to your computer and use it in GitHub Desktop.
Save reimai/6ba8b1139a6f64caf0b53e4fb470bfba to your computer and use it in GitHub Desktop.
pack several python scripts to an executable archive
#!/bin/bash
# packs python scripts to an executable, the first script must be the main script
# example: pyzip quotes find_quotes.py dx.py
name=$(basename "$0")
usage="$name name_of_executable main_script.py [other python scripts]"
executable=${1?usage}
main_script=${2?usage}
scripts=${@:3}
tmp="$$"
mkdir "$tmp"
cp $main_script "$tmp/__main__.py"
for s in $scripts; do
cp $s "$tmp/"
done
zip --junk-paths "$tmp/$executable.zip" $tmp/*.py
echo '#!/usr/bin/env python' | cat - "$tmp/$executable.zip" > "$executable"
rm -r "$tmp"
chmod +x "$executable"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment