How to speed up Pyinstaller EXE load time

In this Python PyInstaller tutorial, we will discuss several techniques and optimizations to speed up your Pyinstaller EXE load time.


Using –onedir mode

It is a well-known fact that Onefile increases the load time for a Pyinstaller application. This is because it adds an extra step to the load process.

This extra step involves unpacking itself into a temporary folder. As you can expect, this can result in several seconds worth of extra load time (depending on the target machine).

This is also probably the easiest, and most effective way to speeding up your application.

Onefile mode has its own fair share of problems. You need to really consider the benefits you will get by switching to onedir mode. And remember, you can always just create a shortcut for your “onedir” folder’s EXE outside it, so that you don’t have to scroll through the whole folder looking for the EXE.


Using Virtual Environments

Virtual Environments are often used when converting Python files to EXE’s. They can drastically reduce the number of libraries that need to be compiled, which reduces the final output size.

This also plays an important role in speeding up your application, because the larger an EXE file is, and the more libraries involved, the slower it will be.

Setting up a Virtual environment is a bit of a lengthy process, so we have discussed this in great detail in a separate dedicated tutorial.


Optimizing your Code

You should always evaluate “why” your application is taking so long to load. Chances are, that your code may also share part of the blame.

Optimizing your code to quickly show some GUI output (or console) as fast as possible should be your goal (generally speaking).

Lazy loading of modules doesn’t really appear to have much of an effect on the load time. But you can work on lazy-loading the rest of your application.

For example, let’s say you have an application which needs to connect to the internet. Before you open a connection/make a request (which will add a delay) you can consider showing some minimal / default GUI to the User.

No need to load the application all at once, rather load it in chunks.

For more advanced uses, you can consider turning to “Python performance profilers” which can even show you the breakdown of your individual functions, and how long each of them are taking.


Windows Firewalls + Signed Applications

This part is actually a bit tricky to explain, and even tricker to implement. But its good to know about this just incase, especially if you plan on making a commercial application.

The Windows firewall is actually responsible for increasing the load-time significantly on Windows. It checks each and over dependency/file loaded by your application, for security reasons. This adds alot of overhead.

To verify this, you can turn of “Real-time protection” in your firewall, and then try running your application. You will notice a significant boost to your load time.

How to get around this? There is no easy way.

The proper way of doing this, is to get a “signed certificate” which marks your application as “trusted”. These certificates are paid however, (yearly charges usually) and unless you have a commercial application, its not going to be worth it.

If you have reached a point where you are considering this, it’s probably best to switch from Pyinstaller to something else. Read the next section carefully.


Last Resort

If you have tried everything, and you still feel that your application is loading too slowly, I can only suggest you switch from using Pyinstaller to some other library.

Pyinstaller is actually one of the slower EXE converters. For those looking for speed, I recommend either cx_Freeze or Nuitka. Take a look at both, and then make your decision. For reference though, they both load about twice as fast than Pyinstaller.


This marks the end of the How to speed up your Pyinstaller EXE load time Tutorial. Any suggestions or contributions for CodersLegacy are more than welcome. Questions regarding the tutorial content can be asked in the comments section below.

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments