Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.035 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; 'example:': 0.03; 'linux,': 0.07; 'subject:file': 0.07; 'python:': 0.09; 'python': 0.11; 'stored': 0.12; 'expects': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'hack': 0.22; 'header:User-Agent:1': 0.23; 'received:emailsrvr.com': 0.24; 'file.': 0.24; 'received:(smtp server)': 0.26; 'distribute': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'feature': 0.29; "d'aprano": 0.31; 'gary': 0.31; 'steven': 0.31; 'file': 0.32; 'quite': 0.32; 'skip:# 10': 0.33; "i'd": 0.34; 'basic': 0.35; 'but': 0.35; 'application': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'little': 0.38; 'to:addr:python.org': 0.39; 'called': 0.40; 'users': 0.40; 'even': 0.60; 'zip': 0.64; 'nobody': 0.68; 'line!': 0.84; 'received:108.166': 0.84; 'archive.': 0.93; 'received:108': 0.93; 'this!': 0.93 X-Virus-Scanned: OK X-Sender-Id: gary.herron@islandtraining.com Date: Tue, 22 Jul 2014 22:30:41 -0700 From: Gary Herron User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Distributing python applications as a zip file References: <53cf38c2$0$29897$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <53cf38c2$0$29897$c3e8da3$5496439d@news.astraweb.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1406093800 news.xs4all.nl 2880 [2001:888:2000:d::a6]:33958 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:75057 On 07/22/2014 09:23 PM, Steven D'Aprano wrote: > A little known feature of Python: you can wrap your Python application in > a zip file and distribute it as a single file. The trick to make it > runnable is to put your main function inside a file called __main__.py > inside the zip file. Here's a basic example: > > steve@runes:~$ cat __main__.py > print("NOBODY expects the Spanish Inquisition!!!") > > steve@runes:~$ zip appl __main__.py > adding: __main__.py (stored 0%) > steve@runes:~$ rm __main__.py > steve@runes:~$ python appl.zip > NOBODY expects the Spanish Inquisition!!! > > > On Linux, you can even hack the zip file to include a shebang line! > > > steve@runes:~$ cat appl > #!/usr/bin/env python > # This is a Python application stored in a ZIP archive. > steve@runes:~$ cat appl.zip >> appl > steve@runes:~$ chmod u+x appl > steve@runes:~$ ./appl > NOBODY expects the Spanish Inquisition!!! > > > It's not quite self-contained, as you still need to have Python > installed, but otherwise it's a good way to distribute a Python > application as a single file that users can just copy and run. > > > Really! 20 years of Pythoning, and I'd never seen this! When was this introduced? Gary Herron