How can I package a python script and modules into a single script?

Noah noah at noah.org
Thu Nov 3 10:15:33 EST 2005


I would like to package my main script and all the
modules it imports into a single script that will
run just as the collection would. It should not
need to package standard Python lib modules -- just
my local modules. This is not the same question
that would be answered with py2exe or py2app. I
don't need to package the script into a binary
along with Python. I expect Python to be installed.
I also don't want to use distutils to install the
script. The script will always run on Unix.

I thought that there might be some way to run a
script package from a tar file. One way would be to
have the package script  untar itself into a temp
directory; run the main script; then  delete the
temporary package directory when done. That sounds
clunky and prone to leave around trash if someone
does a 'kill -9'. However, this might be an
acceptable compromise. I'm sure that I've seen a
tool around like this, but I can't find it anymore.
I checked the usual places (google and sf.net).

I also considered simply cutting and pasting all
the modules I need into one single, giant script,
but that's less appealing than the tarball idea
(unless it could be done automatically).

Yours,
Noah




More information about the Python-list mailing list