Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #75071

Re: Distributing python applications as a zip file

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python.leojay@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'example:': 0.03; 'url:pipermail': 0.05; 'linux,': 0.07; 'subject:file': 0.07; 'python:': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'bug': 0.12; 'stored': 0.12; 'windows': 0.15; '23,': 0.16; 'expects': 0.16; 'to:addr:pearwood.info': 0.16; "to:name:steven d'aprano": 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'hack': 0.22; 'cc:addr:python.org': 0.22; 'file.': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'distribute': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'feature': 0.29; 'message-id:@mail.gmail.com': 0.30; "d'aprano": 0.31; 'steven': 0.31; 'file': 0.32; 'quite': 0.32; 'url:python': 0.33; 'skip:# 10': 0.33; 'basic': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'url:org': 0.36; 'application': 0.37; 'pm,': 0.38; 'little': 0.38; 'called': 0.40; 'users': 0.40; 'url:mail': 0.40; 'even': 0.60; 'ago.': 0.61; 'happen': 0.63; 'zip': 0.64; 'nobody': 0.68; 'jul': 0.74; 'leo': 0.84; 'line!': 0.84; 'url:python-dev': 0.84; 'archive.': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=7Du/e6/gajOxY62FlFONsWCmEnC4KxELw8rfqJhpTRM=; b=IqDIfwmk6tlbEMC9rUF7fVAIWABarXwqUg9/q5Yo0IZIlMX+qT+uTai/ZgOo8UcrP7 eZQdfFrDCmuAe31Ddd4cAObSQxOa1Z+9pXfQnRhR6oHK6fzOxFoldJYzyErw/WQujK0b j8gLdARDyoUccBxVzn+Fq1Yeetkk28iLdTUdoQUjQh+o1p9R1/BZnrL3fd1yXSZYNsb5 Vit0ja3ku5KfOhgfwrWN0Ex6Fv4zy+fqc+NSiXiSIFltAPNmm4ewPSLGQGlvWELytEci 8qDKlEYpqfQJ/4FDXMjA+aI0TDIXjOQXDtb0dsxdlLO/7V2oKn2Gg6qjI+A9W8Ywzmn3 9k8Q==
MIME-Version 1.0
X-Received by 10.220.122.132 with SMTP id l4mr47773912vcr.41.1406104991053; Wed, 23 Jul 2014 01:43:11 -0700 (PDT)
In-Reply-To <53cf38c2$0$29897$c3e8da3$5496439d@news.astraweb.com>
References <53cf38c2$0$29897$c3e8da3$5496439d@news.astraweb.com>
Date Wed, 23 Jul 2014 16:43:11 +0800
Subject Re: Distributing python applications as a zip file
From Leo Jay <python.leojay@gmail.com>
To "Steven D'Aprano" <steve@pearwood.info>
Content-Type text/plain; charset=UTF-8
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.12226.1406104999.18130.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1406104999 news.xs4all.nl 2945 [2001:888:2000:d::a6]:41314
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:75071

Show key headers only | View raw


On Wed, Jul 23, 2014 at 12:23 PM, Steven D'Aprano <steve@pearwood.info> 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.
>

But if you use windows and you happen to use multiprocessing,
please be aware of this bug I encountered several years ago.
https://mail.python.org/pipermail/python-dev/2011-December/115071.html

-- 
Best Regards,
Leo Jay

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Distributing python applications as a zip file Steven D'Aprano <steve@pearwood.info> - 2014-07-23 04:23 +0000
  Re: Distributing python applications as a zip file Gary Herron <gary.herron@islandtraining.com> - 2014-07-22 22:30 -0700
  Re: Distributing python applications as a zip file Chris Rebert <clp2@rebertia.com> - 2014-07-22 22:46 -0700
  Re: Distributing python applications as a zip file Tim Golden <mail@timgolden.me.uk> - 2014-07-23 08:20 +0100
  Re: Distributing python applications as a zip file Chris Angelico <rosuav@gmail.com> - 2014-07-23 17:59 +1000
  Re: Distributing python applications as a zip file Thomas Heller <theller@ctypes.org> - 2014-07-23 10:07 +0200
  Re: Distributing python applications as a zip file Leo Jay <python.leojay@gmail.com> - 2014-07-23 16:43 +0800
    Re: Distributing python applications as a zip file Alan <alan.isaac@gmail.com> - 2014-07-24 05:19 -0700
  Re: Distributing python applications as a zip file Burak Arslan <burak.arslan@arskom.com.tr> - 2014-07-23 15:23 +0300
    Re: Distributing python applications as a zip file Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-24 00:55 +0000

csiph-web