Pyinstaller Reduce Packed Program Size

Pyinstaller Reduce Packed Program Size

When I was packing Xevent Reader with pyinstaller, I created a new conda virtual environment and installed the necessary python packages. However, the size of the packed program is very large, 200MB+, and runs very slow. This problem is solved by using pipenv virtual environment.

Install pipenv

Working environment: Anaconda Prompt

1
pip install pipenv

Create a new folder for the virtual environment.

Setup virtual environment

Get into the folder created.

1
cd <Path of your folder>

Setup the virtual environment.

1
pipenv install

Activate the virtual environment.

1
pipenv shell

Packing

Install necessary packages for your program, including pyinstaller

1
pip install pyinstaller, ...

You can try to run your python script first to test if it runs correctly under this environment.

1
python <YourScript.py>

Download UPX to help further reduce file size and avoid triggering security warnings when running the program on other machines. Copy upx.exe to the location of your script.

Packing. Make sure INFO: UPX is available is prompted in the cmd window.

1
pyinstaller -F <YourScript.py>

Pyinstaller Reduce Packed Program Size
http://example.com/2022/08/16/Pyinstaller Reduce Packed Program Size/
Author
Jiacheng Xie
Posted on
August 16, 2022
Licensed under