Jump to content

  • Log In with Google      Sign In   
  • Create Account

Problem creating an .exe with py2exe


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 PaladinJohn   Members   -  Reputation: 130

Like
1Likes
Like

Posted 11 August 2011 - 08:41 PM

My problem seems like a pretty simple issue, but I don't have any idea how to go about fixing this. I'll show the problem and list the steps I've taken so far in order to fix it.

After creating a game using python 2.7, I tested the game and it worked flawlessly without any bugs. Deciding that I wanted to redistribute it to a few of my friends I looked up some info on what I would have to do and eventually found py2exe. After carefully following all of the directions and creating my .exe, it failed to run. Running it through command line I got the following errors:

Spoiler


(Although I'm sure it's obvious, the name of my program is footBallHell.)

So, clueless as to what to do next I searched up google and found this similar problem on the python forums:

http://www.python-fo...hp?f=15&t=26719

After reading that I dug around through the Python folder and went to:

C:\Python27\Lib\site-packages\pygame

and found a file listed as "_view.pyd"

I believed that this was the file in question that was missing so I copied it into the dist folder hoping it would solve the problem. Unfortunately, it didn't. So, afterwards I went and added it into the directory with the rest of the relevant files as well as the setup.py program I used to create the executable so the program read as follows:

from distutils.core import setup
import py2exe

setup(console = ["footBallHell.py"],
  	author="XXXX",
  	author_email="XXXX",
  	data_files=[('.', ["attack.ogg",
                 		"enemy.gif",
                 		"Field.gif",
                 		"football.gif",
                 		"player.gif",
                 		"save.ogg",
                 		"tackle.ogg",
                 		"freesansbold.ttf",
                 		"_view.pyd"]
           		)]
  	)

After running the setup.py program, it did include the _view.pyd file in the dist folder, but still would not run.

So, I believe I either have the wrong file or there is something else I need to do in order to get the program to run. What I am asking is if there is any one out there that might know how to fix this issue, or, at worst, inform me of another way I can create an executable for Windows out of my python programs that I can distribute to my friends.

Sponsor:

#2 Knackebrod   Members   -  Reputation: 132

Like
0Likes
Like

Posted 13 August 2011 - 05:52 AM

-snip-

Hi, I have written a game with Python too. It imports quite a lot of external modules (though pygame isn't one of them).
I don't have much experience with py2exe, though, as I use cx_freeze to distribute my app and it works perfectly. I made that choice over py2exe long ago, and I don't remember why exactly, but cx_freeze turned out to be better for my needs. I suggest you try it, and see if it works. Go there: http://cx-freeze.sf.net

I might be able to help you with cx_freeze since I know the structure of its output better than that of py2exe.
(PS- If you're interested to see the final result for the game, you can download it. The game itself is frozen with cx_freeze. Then, I made a tiny launcher with NSIS, so that I could bury all the DLLs inside the "data\bin" folder. That way, it's friendlier to the end-user that has just unzipped the game: they don't have to face a bunch of files with cryptic names.)

EDIT - Here is the structure of my setup.py: (sorry about the borked spaces)

import sys
from cx_Freeze import setup, Executable

includefiles = []

if sys.platform.startswith('win'):
 includefiles.append( ("win32\\dll", ".") ) # my custom dlls are there

options = {
"icon": 'win32/citronicon.ico',
"include_files": includefiles
}

mybase = None
if sys.platform.startswith('win'):
    mybase = "Win32GUI"

cible_1 = Executable(
    script = "main.py",
    base = mybase,
    compress = False,
	copyDependentFiles = False,
)
	
setup(
	name = "main",
	version = "0.4",
 	description = u"game name",
 	author = "me",
	options = {'build_exe':options},
	executables = [cible_1]
 )


#3 Serapth   Crossbones+   -  Reputation: 5450

Like
0Likes
Like

Posted 13 August 2011 - 06:43 AM

Your other option is to work from the PyGame's py2exe script

#4 PaladinJohn   Members   -  Reputation: 130

Like
0Likes
Like

Posted 13 August 2011 - 03:42 PM

Thank you both for your replies!

I looked at pygame's py2exe script before, but truth be told, I'm a fledgling in the world of programming, and admittedly know very little about the world of windows and how it actually runs programs. Looking over the script, while I understood some of it, other parts looked completely foreign even with comments. I feel uncomfortable using code that I don't at least understand what each part is supposed to be doing, and a lot of that code contains things that either look like they would be superfluous to my needs, or references stuff that I have no clue whether it's an example or is something that is actually needed. (Such as wildcards. Never heard of them before.)

I tried to find some more in depth documentation of that script, but I was unable to find any such thing.

Knackebrod,

I took a brief look at cx_freeze, and it seems that it's benefits include cross platform support. Your example setup.py was good, but I am still confused about some of the finer details of the script. At this point in time I'm not too worried about surface level changes such as including an icon or installer (Though I did appreciate it in the example so I now know how to do such things when I do put more effort into making a presentable program. I will be checking out NSIS in the future.) Right now I'm looking for a nitty gritty bare bones .exe that I can zip up, send to my friends, and have them delete the file after they're done playing around with it.

One thing that I would like to add that I found in my search for an answer was that someone with a similar problem was told that they can explicitly specify modules to include on the py2exe command line. Unfortunately, all the experience I've ever had with the command line I've learned since installing py2exe a few nights ago and the breadth of my experience with it is getting py2exe to run. I'm very nervous about tinkering around in command line as I don't want to accidentally blow my computer up, but would any one know a way to include the _view.pyd file on that same command line so it (hopefully) compiles into the .exe correctly?

#5 PaladinJohn   Members   -  Reputation: 130

Like
0Likes
Like

Posted 13 August 2011 - 08:32 PM

I got it to work! I'll detail what I did here so if any other clueless beginner stumbles upon these same errors and does a google search, they might be able to compile their game without any issue:

Firstly, to fix the _view problem, I was forced to put the following line of code into my main program (not the setup.py program) in order to call the _view.pyd so that py2exe actually finds it:

import pygame._view

That line of code has absolutely no effect on the program itself.

Afterwards, I kept getting font errors despite making sure to include the font in the list of files. A brief search of the internet helped me to narrow down exactly which part of pygame's py2exe script was responsible for fixing the issue with the font, as well as the sound which was a problem I ran into afterwards. Simply copy/pasting the code from the script did not work, and instead thanks to some advice from the following blog: http://thadeusb.com/...font_and_py2exe I edited my setup.py script appropriately. (Please remember to import os in your setup.py script!)

Here is the final setup.py program I wound up with:

from distutils.core import setup
import py2exe, os

origIsSystemDLL = py2exe.build_exe.isSystemDLL
def isSystemDLL(pathname):
	if os.path.basename(pathname).lower() in ("sdl_ttf.dll", "libogg-0.dll"):
        	return 0
	return origIsSystemDLL(pathname)
py2exe.build_exe.isSystemDLL = isSystemDLL

setup(console = ["footBallHell.py"],
  	author="XXXX",
  	author_email="XXXX",
  	data_files=[('.', ["attack.ogg",
                 		"enemy.gif",
                 		"Field.gif",
                 		"football.gif",
                 		"player.gif",
                 		"save.ogg",
                 		"tackle.ogg",
                 		"freesansbold.ttf"]
           		)]
  	)





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS