making executables smaller

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Jul 27 04:20:25 EDT 2016


On Wednesday 27 July 2016 14:52, Thomas 'PointedEars' Lahn wrote:

> Carter Temm wrote:
> 
>> I’m writing a couple different projects at the moment, and when I compile
>> it into a single executable using pyinstaller, it becomes extremely large.
>> I’m guessing this is because of the modules used. Because I’m not that
>> skilled at python, I put stuff like for example, import sys. I imagine the
>> final project could be made smaller by specifying from something import
>> something_else. but the thing is, I don’t know what smaller I could import
>> with these set of modules. Is there a program that could tell me this.
> 
> I recommend to comment out all “import” statements (for later reference) and
> then use a Python editor like PyDev to generate step by step “from … import
> …” statements for all used symbols that are not yet defined.

What benefit do you think you will gain from changing (let's say):

    import collections
    x = collections.deque(foo)

to:

    from collections import deque
    x = deque(foo)


as far as executable size goes? Do you think that by using from...import... the 
module, and all of its dependencies, won't need to be included?

Or are you just trying to save a handful of bytes ("collections.deque" in UTF-8 
is 17 bytes, compared to "deque" is just 5 bytes)?


Since the OP is talking about saving space, how much space do you expect to be 
able to save using this technique?


-- 
Steve




More information about the Python-list mailing list