Python: Reduce the size of executable file created by PyInstaller on Conda
Introduction
Building a standalone executable file of your application using PyInstaller and Python on a Conda base environment might be a nightmare as the size of the executable file will be so large, 100 - 200 ++ MB. In order to reduce the size of exe file, we will use the packages that are bound to or installed by PIP instead of Conda. So, the trick is uninstall Conda packages and reinstall them again using pip in a new environment where is clean and fresh.
Step-by-Step:
1. Create a new conda environtment:
conda create -n NAME_OF_NEW_ENV
2. Activate a newly created env
conda activate NAME_OF_NEW_ENV
3. Install pip using conda:
conda install pip
4. Install other packages that your application requires using pip, for example:
pip install numpy scipy matplotlib
5. Use conda or pip to show all packages installed in the environment:
conda list
or
pip list
6. Install PyInstaller using pip
pip install pyinstaller
7. Now you are ready to make executable file from Python source code using PyInstaller:
pyinstaller example.py
P.S. To make a one file executable, just use -F or --onefile option for PyInstaller.
Rangsiman Ketkaew