making executables smaller

Daniel Bradburn moagstar at gmail.com
Wed Jul 27 06:21:21 EDT 2016


A couple of things you can try:

* Generate a directory rather than onefile, on the directory you can apply du
-hs * | sort -h -r (or treesize if you are using windows
https://www.jam-software.com/treesize_free) to see which folders / files
are taking up a lot of space. Then once you see what is taking up a lot of
space you can try and figure out why it is being included, maybe you have a
load of unused imports? With pyinstaller you can explicitly exclude modules
you know you won't need with --exclude-module once you've optimised the
directory build you can of course switch back to onefile

* If all else fails you can use upx to compress your binary files (dlls +
exe) which can help reduce the overall size:
https://pythonhosted.org/PyInstaller/usage.html#using-upx

Hope this helps.


2016-07-27 10:20 GMT+02:00 Steven D'Aprano <
steve+comp.lang.python at pearwood.info>:

> 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
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list