Package a Python program to a single Executable file with Pyinstaller

The advantage of packaging a program is that the user do NOT need any programming environment to use the packaged software.

Packaging a program is very common.For example, when you install most of the software, the ‘setup’ installer will install a packaged software into your computer as a folder and add a shortcut of the executable to your desktop.

However, packaging the program into a single file is much more difficult, I’ll explain why later, let us see how to do it for a Python project.

First things first, make sure you have pyinstaller. I’ve used other libraries like py2exe, but pyinstaller is the best in terms of its compatibility, stability, and user-friendly, the list goes on and on.

in the command window

-> pyinstaller  -o image.ico  -F  –upx-dir upxfolder

-c  (default)  open a console window

-w  will NOT open a console window

The biggest problem when packaging, especially to a single file:

can not find some specific library dependencies

these are tons of solutions online, but much are so complex and not direct

these is a very simple solution:

Locate the library you import in your program (the one failed packaging) then move the source code to your current directory with the program you wrote, the CHANGE the name of the source code file and change the library name you import.

The packaging software will then search dependency files from the files you made.

Here’s an example: