How do I convert my pygame program which has multiple python scripts and images to a exe?

独自空忆成欢 提交于 2020-07-15 08:54:06

问题


I have 3 python scripts and many images in folders and tmx files which I want to make it as a single .exe . I wasnt able to find how to convert multiple python scripts and folders to single exe. I was only able to find cxfreeze and similar things for a single python script. Please help.

Thanks in advance.


回答1:


You can add external files to your pyinstaller exe by using add-data. An example I'm using for one of my pygame games:

pyinstaller --onedir --clean --name "MyGame" --icon="images/icon.ico" --add-data "images/*.png:images" --add-data "sounds/*.mp3:sounds" --add-data "sounds/*.wav:sounds" --add-data "fonts/*.ttf:fonts" main.py



回答2:


Create a setup.py file in cxfreeze. You have to pass multiple pyhton files as list in cxfreeze executables. Refere this thread -

Python cx_Freeze for two or more python files (modules)

For separate files like images, you have to include those files explicitly. Below is an example which worked for me on one of the project -

from cx_Freeze import setup, Executable

build_exe_options = {'packages': ['os', 'tkinter', 'matplotlib.backends.backend_svg', 'subprocess'],
                     'namespace_packages': ['mpl_toolkits'],
                     'include_files':['input3.json', 'SF.xlsx', 'SF logo.ico', 'Operative Temperature.pkl',
                                      'Rect_icon.png', 'Soltissim logo.png', 'SF full logo.jpg', 'IES logo.jpg']}

base = None

if sys.platform == 'win32':
    base = 'Win32GUI'

setup ( name = 'Soltissim',
        version = '2',
        description = 'SF GUI',
        options = {'build_exe': build_exe_options},
        executables = [Executable('Soltissim.py', base=base, icon='SF logo.ico'),
                       Executable('SF_English.py', base=base, icon='SF logo.ico'),
                       Executable('SF_French.py', base=base, icon='SF logo.ico')])



Furhter, if you want to create a build from setup which can be then used in program like inno, use following command in terminal - python setup.py build

If you want to create a simple windows installer directly from setup, use - python setup.py bdist_msi



来源:https://stackoverflow.com/questions/62362899/how-do-i-convert-my-pygame-program-which-has-multiple-python-scripts-and-images

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!