How to exclude unnecessary modules and files from packaged python application?

352 views Asked by At

I am trying to package a python GUI application into a .exe file. However, the folder with the exe file includes a ton of unused modules that I have installed, like pygame and numpy. Deleting these useless files and folders does not seem to affect the .exe file at all, but it is extremely tedious to manually do it. This happens when I use PyInstaller, auto-py-to-exe, and py2exe. When I package it into a single .exe file, I still see these unnecessary modules being installed through the console output.

In my code, I never imported modules like pygame and numpy, but they were still in the final folder. In the tutorials I followed, it seemed like this problem was not present, and there were significantly less files. I'm not sure what I'm doing wrong, is it possible that my modules are installed incorrectly?

1

There are 1 answers

0
John Anderson On

You can use the --exclude-module EXCLUDES to exclude modules. See the documentation. There are similar questions already answered in stackoverflow. See this question.