While I was converting my python game file to exe file using pyinstaller, the size came out to be very large(300 MB). I also had used upx which made file exe file even more large(317 MB). The python game file is an offline game. Can anyone provide a solution to this?
Pygame is optionally dependent on numpy, scipy, and PIL. (Or maybe the scipy and PIL come from being optionally dependent on numpy, it makes no difference here)
If you have those installed on your system, PyInstaller will bundle them with your executable. But you probably don't need them. (Unless you're using pygame.sndarray
or pygame.surfarray
, which are backed by numpy).
To exclude them, you can add the following to the excludes
portion of your .spec
file: ['numpy', 'scipy', 'PIL']
It looks like you could also do this as a command line option with multiple uses of the --exclude-module
argument. See https://pyinstaller.readthedocs.io/en/stable/usage.html#cmdoption-exclude-module
Some people also get around this by using virtual environments.
But even assuming you have those 3 libraries bundled, 300 mb is quite large. If you're doing onefile mode, stop doing that for debugging, so you can see the folder names and files included with your project. That will give you more insight.