[Python-Dev] Single-file Python executables (was: Computed Goto dispatch for Python 2)

Donald Stufft donald at stufft.io
Thu May 28 17:39:50 CEST 2015



On May 28, 2015 at 11:30:37 AM, Steve Dower (steve.dower at microsoft.com) wrote:
> Donald Stufft wrote:
> > Well Python 3.4.3 binary is 4kb for me, so you'd have that + your 1KB Python script + whatever  
> other pieces you need.
>  
> For contrast, here are the things you need on Windows to be able to get to an interactive  
> prompt (I don't know how other platforms get this down to 4KB...):
>  
> * python.exe (or some equivalent launcher) 39KB
> * python35.dll 3,788KB
> * vcruntime140.dll 87KB (the rest of the CRT is about 1MB, but is not redistributable  
> so doesn't count here)
> * 26 files in Lib 343KB
>  
> This gets you to ">>>", and basically everything after that is going to fail for some reason.  
> That's an unavoidable 4,257KB.
>  
> The rest of the stdlib adds another ~16MB once you exclude the test suite, so a fully functioning  
> Python is not cheap. (Using compressed .pyc's in a zip file can make a big difference here  
> though, assuming you're willing to trade CPU for HDD.)
>  
> Cheers,
> Steve
>  
>  

You don’t need a "fully functioning Python" for a single file binary, you only
need enough to actually run your application. For example, if you're making
an application that can download files over HTTP, you don't need to include
parts of the stdlib like xmlrpc, pickle, shelve, marshall, sqlite, csv, email,
mailcap, mailbox, imaplib, nntplib, etc.

Of course deciding which pieces you include in the zip file you're appending
to the end of Python is up to whatever tool builds this executable which
doesn't need to be part of Python itself. If Python itself gained the ability
to operate in that manner than third party tools could handle trying to do the
optimizations where it only includes the things it actually needs in the stdlib
and excludes things it doesn't. The key thing here is that since you're doing
a single file binary, you don't need to have a Python which is suitable to
execute random Python code, you only need one that is suitable to execute this
particular code so you can specialize what that includes.

---  
Donald Stufft
PGP: 7C6B 7C5D 5E2B 6356 A926 F04F 6E3C BCE9 3372 DCFA




More information about the Python-Dev mailing list