Kabilan
Kabilan

Reputation: 11

How to improve the speed of python exe file?

I am using pyinstaller to generate an exe file for my python script. When I run my exe file, it takes about 15 seconds to show my output. How can i reduce this time?

EXE file size is 26 mb. Any suggestions for reducing my exe file size would also be helpful.

This is my python script

import pandas as pd
import datetime
print(datetime.datetime.now())
df = pd.read_excel("D:\sample.xlsx")
print(df)

I create the exe of my script using pyinstaller, like so:

pyinstaller --exclude tkinter -F sampleProject.py

Upvotes: 1

Views: 3152

Answers (1)

Roland Smith
Roland Smith

Reputation: 43495

How can i reduce this time?

Simply put: don't use PyInstaller, or use an SSD. A pyinstaller program has to do a lot of extra work before it can run your script.

Every time you run it, it creates a temporary directory where it unpacks the executable. This means unpacking Python, its shared libraries and whatever modules you used. Only after than has happened can it start Python and have it load your program.

A compounding problem is that compared to e.g. Linux, ms-windows filesystem I/O is slow.

EXE file size is 26 mb. Any suggestions for reducing my exe file size would also be helpful.

Again, this is because a copy of Python, its libraries and all required modules such as pandas is contained in this executable. On my system, the installed versions of Python 3.7 and Pandas use 160 MiB of disk space. So 26 MiB isn't that bad, really.

Using PyInstaller only makes sense if you want to distribute one python program to other ms-windows users. (UNIX-like systems generally have Python easily available via their package manager.) If they are using multiple Python program it's probably more efficient to just install Python on their machine. That will greatly reduce size and startup time of the programs.

Upvotes: 2

Related Questions