4

I know I'm not the first to ask, but the other answers on the forum could not help me, so I'm asking. I have a short (181 line) python script that only has the imports

import numpy as np import matplotlib.pyplot as plt from matplotlib.widgets import Slider, RadioButtons

and runs up a interactive math tool with sliders and radio buttons. But when I built it with pyinstaller, I end up with a massive (90 MB) dist folder that appears to include all sorts of unnecessary packages like babel and cryptography. The executable inside takes around 5 seconds or so to actually display the figure. When I run it with the --onefile option, things seem no better, as I get a 43 MB executable that takes even longer, about 10 seconds, to display the figure.

I'm prety sure it's not the script's fault because in Spyder, it takes less than a second to open up. I'm suspecting that it is because of all the extraneous packages. If so, how do I get pyinstaller to exclude them, and if not, then what is the likely issue? Thanks.

EDIT: Also, I am doing all of this in a conda virtual environment, which I read somewhere should already help to make pyinstaller's executable smaller. After creating the environment, the only packages I directly installed were pyinstaller, spyder, numpy, and matplotlib.

Haji Giray
  • 43
  • 1
  • 8
  • 1
    This should be helpful. https://stackoverflow.com/questions/9469932/app-created-with-pyinstaller-has-a-slow-startup – Vinay Jaju Apr 25 '19 at 05:46

1 Answers1

2

This happens because when creating the executable you are also using the libraries, what I do is import only what is necessary for the program and then compile it, for example, for an application in Tkinter:

from tkinter import Tk, Label
root = Tk()
Label(root, text='Label').pack()
root.mainloop()