In order to get around this, I remembered using a project called cx_Freeze. cx_Freeze allows you to distribute a Python program as an executable - removing the need for Python and libraries that your program requires. You can run cx_Freeze from the command line or by creating a distutils setup script. I looked around to find a suitable script for use with pygame, all of the scripts I tried resulted in the error:
pygame.error: File is not a Windows BMP file
This is because Pygame doesn't support loading PNG files without the use of SDL_image. With this in mind, it's important to tell cx_Freeze where your libSDL installation is. You can do this by assigning a path to bin_paths_include. I created my binaries using the following script:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import platform | |
from cx_Freeze import setup, Executable | |
if platform.system() == 'Windows': | |
bin_inc = 'C:\\Python27\\Lib\\site-packages\\pygame' | |
name = 'seprcph.exe' | |
else: | |
bin_inc = '/usr/lib' | |
name = 'seprcph' | |
# Dependencies are automatically detected, but it might need | |
# fine tuning. | |
buildOptions = dict(packages = ['pygame'], excludes = [], | |
include_files = ['assets/images/', 'data/'], | |
bin_path_includes=bin_inc) | |
base = 'Console' | |
executables = [ | |
Executable('seprcph/main.py', base=base, targetName=name) | |
] | |
setup(name='seprcph', | |
version = '1.0', | |
description = 'Trains across Europe', | |
options = dict(build_exe = buildOptions), | |
executables = executables) |
python2.7 cx_build.py build
This will create a new directory called build - inside of which will be another directory containing the created binary and required libraries.
No comments:
Post a Comment