0

I have worked in Python before but not as a developer and i'm having issues with pyinstaller. I want to convert to .exe a very simple python script that only uses os and pandas but the file is very heavy (>300Mb for a 2k script) because pyinstaller loads all the libraries in Anaconda.

I have tried the code below with --exclude but nothing happens:

pyinstaller --hidden-import pandas --hidden-import os --exclude * main.py

Someone knows how to this the right way?

  • did you check out : https://stackoverflow.com/questions/47692213/reducing-size-of-pyinstaller-exe – JonSG Feb 01 '23 at 16:22
  • you need to create a new virtual enviornment that only has pyinstaller and pandas installed. Then create the exe. – Alexander Feb 02 '23 at 00:59

1 Answers1

0

pandas is a dependency hell... it imports everything under heaven and hell whether you require it in your program or not run pyinstaller first time with this this flag --onedir

pyinstaller  --onedir --hidden-import pandas --hidden-import os --exclude * main.py

..go to "dist" directory

and in the generated dist "directory" you will see directories for each imported module. delete one by one..and see if your program executes till you have tried deleted all modules which are not required for your program to run

keep a note of those directories (modules) without which your program runs fine and re run pyinstaller

like in this example

pyinstaller --hidden-import pandas --hidden-import os --exclude-module 
"matplotlib" --exclude-module "PIL" --exclude-module "IPython" 
--exclude-module "ipykernel" --exclude-module "qtpy"  
--exclude-module "nbformat" --exclude-module "scipy" 
--exclude-module "sklearn"  --exclude * main.py

alternatvely make a spec file by running

pyi-makespec main.py

Edit the genrated spec file to exclude/include modules you need

and then run pyinstaller using that spec file

pyinstaller main.spec

geekay
  • 340
  • 1
  • 5