4

I'm quite new to programming. I've recently made a simple snake game using python and pygame. Of course, I can play my game easily by running the .py script, but in wanting to share it with my less computer literate friends, I went on to try to figure out how to compile my code into a single .exe to make it easy for them.

I've tried py2exe and cx_Freeze, both giving me a dist or build directory with an .exe and several other files (dependencies). This does work, since I'm able to zip up the whole folder and distribute via .zip, but it's not ideal. I want to be able to wrap it all up in one file.

So I started googling 'how to compile python into a single exe'. However, unlike many of the programming problems I have tried googling before, I just can't get a straight, reliable answer. So far the most recent reliable answer I've tried gives me this setup.py script:

from distutils.core import setup
import py2exe, sys, os

sys.argv.append('py2exe')

setup(
        options = {'py2exe': {'bundle_files': 1, 'compressed': True}},
        windows = ['snek.py'],
        zipfile = None
        )

# Python 3.4.4, py2exe 0.9.2.2; modules used: pygame, random

Still, it gives me a whole folder instead of a single .exe, which the program cannot run without.

So, I come to you, the all-knowing, the great, stackoverflow, with two questions.

Just in case I missed anything: how do you suggest I achieve my single .exe dream?

And: why the hell is this so difficult?

ning
  • 1,823
  • 1
  • 19
  • 25
  • Did you try Nuitka? – mbdevpl Oct 30 '16 at 16:11
  • Python wasn't created to compile to .exe file and many people still don't need .exe file so it is still so complicated. BTW. `py2exe` (and similar) creates self-extracting .zip file with extension .exe, not real .exe file (like C/C++ compiler does). – furas Oct 30 '16 at 16:17

1 Answers1

5

This question is already answered here: py2exe - generate single executable file

PyInstaller will create a single .exe file with no dependencies; use the --onefileoption. It does this by packing all the needed shared libs into the executable, and unpacking them before it runs, just as you describe (EDIT: py2exe also has this feature, see minty's answer)

Community
  • 1
  • 1
YpsilonZett
  • 100
  • 1
  • 7
  • Yes, those are the answers I've tried before. The answer by the user Minty is in fact my current 'solution', as from my question (I'm using the same code!) – ning Oct 31 '16 at 02:29