Thursday, 12 September 2013

PyInstaller & Pygame Single Executable: Couldn't Open File

PyInstaller & Pygame Single Executable: Couldn't Open File

I finished a game using Pygame and I am trying to combine all of the files
into a single executable. I am using this tutorial
http://irwinkwan.com/tag/pyinstaller/ Here is what I have in my code
def resource_path(relative):
if hasattr(sys, "_MEIPASS"):
return os.path.join(sys._MEIPASS, relative)
return os.path.join(relative)
bg = "dbzttt_bg.jpg"
bg = resource_path(os.path.join("", bg))
I just reassigned it to the same variable because I didn't want to rename
all the variables.
This is the command I am running from command prompt:
python pyinstaller.py --onefile ../dbzttt.py
It does what it has to and when I click on the executable, I get the error:
Traceback (most recent call last):
File "<string>", line 63, in <module>
pygame.error: Couldn't open
C:\Users\Josh\AppData\Local\Temp\_MEI57642\dbzttt_bg.jpg
Does anyone know as to why I am getting this error? The tutorial says to
add this line to the spec file:
Tree('data', prefix='data'),
My data is located two directories back from my spec file so my Tree is
like this:
Tree('../../', prefix='../../'),
Is that the way the author intended it to be used, or have I misunderstood
how to use the Tree function?
Any and all help is greatly appreciated. I have about 10 images and a
font-type that I want to include into a single executable so I can upload
my game to a site for others to download. If there are other alternatives,
please let me know. I have tried py2exe, but I've had even worse luck for
that.

No comments:

Post a Comment