I think you're making it more complicated than it needs to be.
I just took the example from the pygame website, and I took out all the crap
that failed (presumably because it was for an older version of Pygame).
Then I ran it, and out popped a Build directory with an EXE inside.
Then I copied my data directories over to the Build folder, zipped it up,
and sent it to people, and it worked fine.
I'll attach the script.
I don't really see why you're making such a complicated batch file for this.
You could put all of this scripting stuff inside the setup.py itself, and
just use it that way.
This is confusing and unnecessarily complicated.
It's not necessary to import modules yourself.
Py2EXE will go through your code and determine all dependencies, and build a
library.zip for you.
The only issue that could arise is if you're generating import strings
dynamically at runtime and eval()ing them or something, but you probably
shouldn't be doing that anyway.
-Luke
On Dec 22, 2007 1:39 PM, TW <[EMAIL PROTECTED]> wrote:
>
>
> Hi Laura,
>
> I just got through reading the Allan Harris spin on the issue.
> Also another short sample and both use different variable names when
> asking for directories.
>
> One shows an include statement and another a PY_DIr name. It is so
> confusing to try and figure out who is right and what is the real format.
>
> I did read enough to try something and will see what happens. The need
> for a dictionary and the path as the key, or the sub directory as the key
> then I will try that and see if it works. But that is what I built in my
> batch file...See example below, at bottom.
> At the moment I have all the modules in the same directory and tried
> listing them, but the error comes when running the .exe and the error is
> on
> the very first import. As if the setup did not include them. So, there
> comes
> the include statement which is only there on one tutorial I found.
>
> Just getting the modules imported, the data files also, is what I need.
> Also, the glob.glob( command is also mention in one place, but not in
> another...
>
> Very confusing, if just one tutorial by the person who wrote py2exe and
> pygame2exe is all that is need that explains each command in detail and
> not
> just the list from the help menu.
> Some simple and not so complex, a simple tutorial on it all!
>
> Bruce
>
>
>
> http://www.py2exe.org/index.cgi/WorkingWithVariousPackagesAndModules
>
> lists some common problems people have had with certain packages and
> modules.
>
> Laura
>
> SAMPLE BATCH FILE FOR THE EXECUTE:
> @echo off
> rem NOTE: This has -w switch deleted when running python25 py2exe FOR IT
> IS
> INVALID!
> rem Batch file to automate creation of Python executables...
> rem ...using py2exe
> echo Making Temp Files!
> rem Contents= set fileName=
> copy config\1.txt config\temp1.bat
> rem Contents= set dirName=
> copy config\2.txt config\temp2.bat
> if "%1"=="/i" goto inp4con
> if not "%1"=="/I" goto line4cmd
> :inp4con
> echo (After each input press return,
> echo Then press ctrl Z and return again)
> echo Enter the file name whose executable you want to create:
> echo (...use relative or absolute path)
> rem BELOW IS FOR CONSOLE INPUT OF THE NAME INSTEAD OF FROM THE COMMAND
> LINE:
> copy config\1.txt + con config\temp1.bat
> echo Enter the setup name to be created:
> echo (...should be same as file name, without the extension of course!)
> copy config\2.txt + con config\temp2.bat
> goto making
> :line4cmd
> rem Inserting the file and dir name entered on command line
> echo %1.py >> config\temp1.bat
> echo %1 >> config\temp2.bat
> if "%2"=="/m" goto modules
> if not "%2"=="/M" goto making
> rem Inserting the module list from a file pre-made
> :modules
> echo Modules?
> if "%3"=="" goto making
> rem Contents= setup(includes=[
> copy 3.txt + %3 config\temp3
> echo ]) >> config\temp3
> :making
> call config\temp1.bat
> rem del config\temp1.bat
> call config\temp2.bat
> rem del config\temp2.bat
> ::Now you are exporting the echo to the file!
> echo Now making the setup file:
> echo from distutils.core import setup > config\set.py
> echo import py2exe >> config\set.py
> rem echo import pygame2exe >> config\set.py
>
> rem NOW TELL IT TO MAKE AN EXECUTABLE:
> echo setup(console=["%fileName%"]) >> config\set.py
> if not exist config\temp3 goto d4dir
> copy config\set.py + temp3 config\set.py
> rem del config\temp3
> :d4dir
> echo setup(name="%dirName%", >> config\set.py
> echo scripts=["%fileName%"], >> config\set.py
> echo ) >> config\set.py
> python25 config\set.py py2exe
> rem del config\set.py
> echo The executable has been created in \dist\%dirName%.exe
> echo errorlevel
>
>
#make standalone, needs at least pygame-1.5.3 and py2exe-0.3.1
from distutils.core import setup
import sys, os, pygame, shutil
import py2exe
#setup the project variables here.
#i can't claim these will cover all the cases
#you need, but they seem to work for all my
#projects, just change as neeeded.
script = "game.py" #name of starting .PY
optimize = 2 #0, 1, or 2; like -O and -OO
extra_modules = ['pygame.locals'] #extra python modules not auto found
#create the proper commandline args
args = ['py2exe', '-O'+`optimize`]
#args.append(','.join(pygame_modules + extra_modules))
sys.argv[1:] = args + sys.argv[1:]
project_name = os.path.splitext(os.path.split(script)[1])[0]
#this will create the executable and all dependencies
setup(console=[script])
#also need to hand copy the extra files here
def installfile(name):
dst = os.path.join('dist', project_name)
print 'copying', name, '->', dst
if os.path.isdir(name):
dst = os.path.join(dst, name)
if os.path.isdir(dst):
shutil.rmtree(dst)
shutil.copytree(name, dst)
elif os.path.isfile(name):
shutil.copy(name, dst)
else:
print 'Warning, %s not found' % name
pygamedir = os.path.split(pygame.base.__file__)[0]
installfile(os.path.join(pygamedir, pygame.font.get_default_font()))
installfile(os.path.join(pygamedir, 'pygame_icon.bmp'))