Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reduce pyinstaller executable size

I have only one line of code input() written in python and packed with pyinstaller with option --onefile. The exe file is 4577 kB which is almost 5Mb. How can I reduce its size or exclude some auto-bundled libraries?

like image 598
Jakub Bláha Avatar asked Dec 19 '22 06:12

Jakub Bláha


1 Answers

Ah, You are not creating the build in a separate virtual environment.

Create a virtual environment just for build purpose and install the packages you need in this environment.

in your cmd execute these to create a virtual enviornment

python -m venv build_env

cd build_env

C:\build_env\Scripts\Activate

you will see this >>(build_env) C:\build_env

Install all the packages you need for your script, start with pyinstaller

pip install pyinstaller

Once you are all installed, build the exe as before. The exe built using the virtual environment will be faster and smaller in size!! For more details check https://python-forum.io/Thread-pyinstaller-exe-size

like image 133
Sudath Murari Avatar answered Dec 21 '22 11:12

Sudath Murari