0

I have written an python application UI using Pyside2 on Windows 10. I also use packages like numpy,scipy. I actually need to deploy the application. i tryed pyinstaller -onefile, my app is around 100 Mo but is too slow to be acceptable. the -one dir option is less slow but always too much and bulky (250 Mo). So i find out Cython and succesfully compiled the main.py file into an exe using gcc on Windows 10 (it has needed mingw64 installation). The execution and utilization speed is good but the library to embed with an installer like inno setup is too big (around 550 Mo).

My question is : Is there any way to reduce the size of python library by at least 70 % on Windows 10?

Attila90
  • 9
  • 3
  • I'm puzzled what you're doing that compiling with Cython adds 300 MB(?) to the file size. That doesn't seem plausible. – DavidW May 04 '21 at 10:59
  • I just compile the main.py which is around 3 Mo. But, to make it run on an other computer, i have to send all the dll and packages of my python environment. How can i reduce the size of my environment ? – Attila90 May 04 '21 at 11:19
  • I think that's a lot of what PyInstaller does: work out which packages you actually need. I think you're best looking at mixing PyInstaller with Cython. – DavidW May 04 '21 at 11:25

1 Answers1

0

From my point of view, it won't be possible. The problem with libraries such as numpy or scipy is, that they depend on dll-files. Those are the 'heavy weights'. Just examine the site-package folder and check the pure size of numpy or scipy. E.g. in my virtual environment, scipy has a size of 100Mb, half of the size is caused by dlls, scipy depends on. Keep in mind, that all those dependencies will be packed into the executable.

Your slow execution time is caused by the size, because when a pyinstaller based executable is launched, it unzips all the packed files into a temporary folder called _MEI... . Latter can be found on C:\Users...\AppData\Local\Temp, but will be deleted after the execution.

What you could do is to exclude all those 'heavy weights' from your executable and link them dynamically on runtime. You would get a small executable, that may start faster.

The Disadvantage: You must ship all the excluded dependencies with your executable and make sure to manage the needed imports properly.

If you want to know, how to exclude files, have a look at those

How to remove/exclude modules and files from pyInstaller?

https://pyinstaller.readthedocs.io/en/stable/spec-files.html

stranger0612
  • 301
  • 1
  • 2
  • 12
  • Thanks for your reply ! So i conclude that python isn't a good language to share an executable as it is 'too heavy weights' even for simple application. – Attila90 May 07 '21 at 09:10
  • Kind of. If you create an executable, with only the standard library, your executable will be around 10Mb. But the main problem will be any library itself if it has a certain size or depends on other files. Hence I wouldn't say, that this is a pure Python problem. Its more how you bundle and distribute your executables. Maybe, try my dynamically approach and pack that approach with inno setup? As far as I know, this tool will work as an installer? So the enduser must only install your tool, and all dependencies will be unzipped by inno? – stranger0612 May 07 '21 at 10:07