CPSuperstore
CPSuperstore

Reputation: 653

How to convert a pygame application with multiple modules to .exe

I have a pygame application which I would like to convert to .exe format. Pygame2exe (https://pygame.org/wiki/Pygame2exe) works nicely EXCEPT I am unable to figure out how to do this conversion with a project that has more than one custom module.

For example:

python_project/
    main.py
    other.py

I need to compile both modules, and merging them is not an option. I have been working at this problem for a few weeks, and have not found any solutions.

I know it is possible, because I had it working, and then formatted the only hard drive that had a copy of the code without realizing I had not made a backup.

EDIT

Thank you Michael. I just had to make a small change to the setup.py file you provided to make it font compatible. Here is the full setup.py file

from distutils.core import setup
import py2exe
import os

origIsSystemDLL = py2exe.build_exe.isSystemDLL
def isSystemDLL(pathname):
       if os.path.basename(pathname).lower() in ["sdl_ttf.dll"]:
               return 0
       return origIsSystemDLL(pathname)
py2exe.build_exe.isSystemDLL = isSystemDLL
setup(windows=['main.py'])  

(taken from Pygame font not working after py2exe)

Thanks again.

Upvotes: 1

Views: 557

Answers (1)

Michael
Michael

Reputation: 426

if you are using python 3.3 or 3.4, you can use py2exe. install through pip, pip install py2exe in cmd note: if 'pip' is not recognized as an internal or external command, navigate to the directory in which python is installed,/scripts probably: C:\python34\scripts

make a setup script called setup.py, with just the three lines of code

from distutils.core import setup
import py2exe
setup(windows=['filename.pyw']          #probably pyw in windows, will be name of main file

then open command prompt in the directory where the main file and setup.py are located, and type setup.py py2exe DO NOT USE or filename.pyw in the setup script, use the name of the main module.

this will make a folder called dist, (you can safely get rid of '__pycache_') containing all the files your exe needs to run! you will probably want to make an installer, I would recommend Inno Setup (http://www.jrsoftware.org/isinfo.php)

Upvotes: 2

Related Questions