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

Alex Martelli aleax at mail.comcast.net
Thu Nov 3 10:42:37 EST 2005


Noah <noah at noah.org> wrote:

> 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

Make a zipfile with the .pyc of all the modules you want; put a small
text header right before it to import the mainscript and run its main
function; that's it, thanks to Python's ability to import from zipfiles.

There's a recipe for that in the Python Cookbook (2nd edition).

(I believe py2app doesn't need to package the standard library, either,
since it comes with MacOSX 10.3 and later, but I haven't checked).


Alex



More information about the Python-list mailing list