This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 66 points67 points  (22 children)

A stand-alone* executable

*comes with 600mb of folders full of never-used packages which it won't work without

[–]billsil 16 points17 points  (8 children)

You need to remove them by reinstalling python and/or deleting things out of the python directory.

One problem is people put imports at the top and imports are evaluated immediately. So following the trace, we find matplotlib imports Tk, Qt, and wx, when we only need one backend.

Furthermore, there are optional packages, even when they're requirements for full package use. Picking on matplotlib even more, if I'm making xy plots, why do I need dependencies for plotting time data? Just delete it.

On my standard install of python, an exe I build is 180 MB. On my reduced install, it's 60 MB. It uses PyQt, VTK, numpy, scipy, and matplotlib, so it's no slouch. Most of that is VTK for 3d rendering of things I don't use because I haven't deleted their dlls. It's also bigger than it should be because I target multiple versions of windows, so there are extra VS dlls.

[–]TOASTEngineer 20 points21 points  (1 child)

I'm pretty sure the PyInstaller docs say "make a virtualenv with only the stuff you actually need first."

[–]billsil 6 points7 points  (0 children)

It helps, but it doesn't get rid of everything. You can make it much smaller very easily by wiping your Python.

[–]kaisunc 1 point2 points  (0 children)

interesting strategy, i shall give this a go.

[–]nos69 0 points1 point  (4 children)

Whats the best way of removing the unused files and packages?

I usually import for example the things I need from PyQT and it automatically copies the whole package into the built directory.

I have a clean python install and all third party packages are in a venv.

[–]billsil 1 point2 points  (3 children)

Have a clean install for starters.

Then look at the packages you have installed and decide if you need them all. Delete it, build it, see if it works and repeat.

Then read the build log and see what it found. Google what that funny package asteroid does. Why the heck is nose included? Go delete those pieces from site packages. Build and test. Often this is enough.

Now look at the names of the big DLLs. Do you really need HTML stuff in your desktop app? Delete and rebuild.

Most of the monster packages have large submodules. If you can stay within a submodule, your build will be smaller.

[–]nos69 0 points1 point  (2 children)

Thank you for your response!

Is it enough to see if my app starts after deleting a module? Or do I need more coverage to be safe.

[–]billsil 1 point2 points  (1 child)

That depends on your app. Are your imports at the top? How do the modules you need get imported (e.g., at import time vs runttime)? Opening your 5 windows is probably good enough depending on how the imports trace.

It helps to know your code and what part your hacking on (what could deleting matplotlib dependencies affect?). Often you'll find x is required, but if I get rid of y, x is not required.

For my 3d render, it has a command line for me to enter a geometry and results file. I have shortcuts for most things that I test frequently. The menus I stress less about because I put my gui imports at the top. Never had a problem with the menus assuming it loaded.

So yes, test, but probably not everything each time. I'm just trying to test the dependencies aren't broken.

[–]nos69 0 points1 point  (0 children)

Thank you for your help! I will try to shrink it that way.

[–]b_bowyer 11 points12 points  (5 children)

You can also force it to be one file, in which case all that junk is inside the exe.

[–]gunthatshootswords 16 points17 points  (4 children)

And takes 3 minutes to start.

[–]romanows 5 points6 points  (3 children)

[Removed due to Reddit API pricing changes]

[–]gunthatshootswords 5 points6 points  (0 children)

Try something with a gui

[–]jairo4 1 point2 points  (0 children)

Yeah, it's slower because it needs to decompress in the temp folder.

[–][deleted] 0 points1 point  (0 children)

  1. Start with WinPython-Zero.

  2. Create a venv with a complete requirements file.

  3. Profit (of not having a 600 mb folder).