Search code examples
pythonpyinstaller

Anaconda Python to EXE with Pyinstaller - huge binary and slow execution


I'm in the process of attempting to convert a Python script to compiled exe to allow me distribute to a number of clients. I have never attempted this before, so am unsure over what to expect regarding size of the distributed files etc.

An example (cut down) version of the script is:

import matplotlib.pyplot as plt


group_size=[10]
subgroup_size=[10,10,10,10,10,10,10,10,10]

a, b, c, d,e,f,g,h,i =[plt.cm.Blues,plt.cm.Blues,plt.cm.Blues, plt.cm.Reds,plt.cm.Reds,plt.cm.Reds, plt.cm.Greens,plt.cm.Greens,plt.cm.Greens]

fig, ax = plt.subplots()
ax.axis('equal')
mypie, _ = ax.pie(group_size, radius=3, colors= [a(0.90)],startangle=90 )
plt.setp( mypie, width=0.5, edgecolor='black')

# Second Ring (Inside)
mypie2, _ = ax.pie(subgroup_size, radius=3-0.5,  colors=[a(.9), b(0.2), c(0.2),d(.2),e(.2),f(.2),g(.9),h(.2),i(.2)],startangle=90,counterclock=False)
plt.setp( mypie2, width=0.5, edgecolor='black')
plt.margins(0,0)

mypie3, _ = ax.pie(subgroup_size, radius=3-1.0,  colors=[a(.9), b(0.8), c(0.6),d(.2),e(.6),f(.2),g(.9),h(.7),i(.2)],startangle=90,counterclock=False)
plt.setp( mypie3, width=0.5, edgecolor='black')
plt.margins(0,0)

mypie4, _ = ax.pie(subgroup_size, radius=3-1.5, colors=[a(.9), b(0.8), c(0.6),d(.2),e(.6),f(.4),g(.9),h(.7),i(.5)],startangle=90,counterclock=False)
plt.setp( mypie4, width=0.5, edgecolor='black')
plt.margins(0,0)

mypie5, _ = ax.pie(subgroup_size, radius=3-2,  colors=[a(.9), b(0.8), c(0.6),d(.8),e(.6),f(.4),g(.9),h(.7),i(.5)],startangle=90,counterclock=False)
plt.setp( mypie5, width=0.5, edgecolor='black')
plt.margins(0,0)

mypie6, _ = ax.pie(subgroup_size, radius=0.5,  colors=[a(.999)],startangle=90,counterclock=False)
plt.setp( mypie6, width=0.9, edgecolor=a(0.999))
plt.margins(0,0)

# show it
plt.show()

It doesn't do anything clever - draws a nested pie chart as per the screen shot enter image description here

Using Pyinstaller with "Pyinstaller --onefile --windowed --clean wheel.py" this compiles successfully to an executable Windows binary as can be seen in the second screenshot. enter image description here

However, the binary is 330Mb in size and takes about 20 seconds to load / start. (I appreciate that the exe is rolling up the Python interpreter - so the size might be what it is)

My question(s):

(1) Is there a "better" (ie smaller binary / quicker load) way to do this? (Am I missing something) (2) Is there a "better" way to deploy an application written in Python?

(I am using Python as I am using matplotlib extensively to generate modified nested pie charts and this has proved to be the most reliable). Sadly, I can't get my clients to install Python -- a single file install is the lowest barrier to entry.

Any pointers greatly received.

Edit: So it transpires that the file size is dictated by the Python interpreter - the same binary size is created create my own GUI using TKinter.


Solution

  • So it appears that the "issue" is compiling into a single file. This is unpacked every time the exe file is executed. So, removing --onefile speeds the execution. Now I need an installer file!!