py2exe

Hi people

I’m trying make a .exe from my demo game. I used py2exe with my gtk programs and others. But i can’t get the right point in panda yet.

My proto-code is:

from distutils.core import setup
import py2exe
import glob
import sys

#sys.path.append(‘src’) # o código fonte ta aqui

opts = {
‘py2exe’: {
“packages”:[“direct”]
}
}

setup(
name = ‘Particulas’,
version = ‘1.0’,
description = ‘Particulas’,
author = ‘Labcart’,
url = ‘’,
download_url = ‘’,
license = ‘GPL’,

 windows = [{'script': 'main.py'}],#main script  
 data_files=[('textures', glob.glob('textures/*.*'))],  

)

It compile allright, but when i execute i got a “see log file”. Ok when i open log file a see nothing :open_mouth:
Someone can gimme a little help with it?

Thanx

Have you tried using packpanda instead?

David

David

Maybe i’m wrong … but packpanda create a package and not compiled files. I want compile files 'cos i guess i’ve frame rate gain.

I change my code in setup.py. It compiles fine but when i execute i have again “see log file” and now with this message:

Traceback (most recent call last):
File “main.py”, line 32, in
File “direct\particles\ParticleEffect.pyo”, line 197, in loadConfig
AssertionError: okflag at line 106 of c:\p\panda3d-1.5.4\built\include\virtualFileSystem.I

Yes, my demo got particles, but i didn’t understand a nut about this.
My new setup.py code:

my PY2EXE setup.py, works with the nasty \direct\src structure and it’s init.py

from distutils.core import setup
import os, glob, py2exe

##################################
PANDA_DIR = ‘c:\Panda3D-1.5.4’
##################################

directInit = os.path.join(PANDA_DIR, ‘direct/init.py’)
tempDirectInit = os.path.join(PANDA_DIR, ‘direct/__init__TEMP.py’)
tempNameDirectInit = os.path.join(PANDA_DIR, ‘direct/__init__TEMPNAME.py’)
def swapFileNames():
os.rename( directInit, tempNameDirectInit )
os.rename( tempDirectInit, directInit )
os.rename( tempNameDirectInit, tempDirectInit )

if empty init.py already exist, swap the names only (I’d like my HD clean),

otherwise rename the original into “temp” and create new EMPTY init.py

if os.path.exists(tempDirectInit): swapFileNames()
else:
os.rename( directInit, tempDirectInit )
emptyDirectInit = open(directInit,“w”)
emptyDirectInit.close()

try:
P3Dpackage_dir={}
directNpandac=[‘direct’,‘pandac’]
for d in directNpandac:
P3Dpackage_dir[d]=os.path.join(PANDA_DIR, d)
directTree=[ ‘direct.’+d for d in os.listdir(’%s\direct\src’ %PANDA_DIR) ]
for d in directTree:
P3Dpackage_dir[d]=os.path.join(PANDA_DIR, d.replace(’.’,’/src/’))
P3DmissingDLLs=glob.glob(os.path.join(PANDA_DIR, ‘bin/*.dll’))

some C/C++ runtime libraries, machine without these .dlls will crash Panda3D

runtimeLibraries=glob.glob(os.path.join(PANDA_DIR, ‘bin/.manifest’))+
glob.glob(os.path.join(PANDA_DIR, 'bin/vcredist
.exe’))

############PY2EXE CONVERSION############
setup(
windows=[ { ‘script’ : ‘main.py’,

‘icon_resources’ : [ ( 1, ‘myLogo.ico’ ) ],

           } ],

zipfile = None,

 options = {
    'py2exe': { 'optimize' : 2,
                'excludes' : [ 'Tkinter' ],
                'dist_dir' : 'dist/'},
              },
 data_files = [
    ( 'etc', glob.glob(os.path.join(PANDA_DIR, 'etc/*.*')) ),
    ( '.', P3DmissingDLLs ),
    ( '.', runtimeLibraries ),
    ("textures", glob.glob("textures/*.*"),
 ] ,
 packages = directNpandac + directTree,
 package_dir = P3Dpackage_dir,
 )

########end_of_PY2EXE CONVERSION#########
finally:

restore direct_init_.py name, leave the empty one there,

so in the future, only need to swap the names, instead of creating it over and over again

swapFileNames()
print ‘\direct_init_.py filename restored :smiley:\n’

This code is a modified version from this thread https://discourse.panda3d.org/viewtopic.php?t=3579

about speedups, since panda (the engine itself) is written in c++. it gives you all the speed of compiled code already. python is just used to controll that code, it usualy doesnt slow down anything. if your application is slow use pstats to see where’s the problem. so far i never found python to be the slow part.
btw. i’m not so sure if py2exe compiles anything or just wrapes your code into a exe-file which is able to run without a seperate python installation.

using packpanda (as suggested by drwr) is recommendet. it creates an easy to use installer.exe which will add start-menu folders etc. something the windows-users are very comfortable with.

No doubt it’s trying to load a .ptf file that’s not included in your archive.

But the thread you’ve linked is a very old thread, that dates back to before we had packpanda. Now that we have packpanda, there’s not really a good reason to use py2exe, unless you have some personal reasons. There’s no performance advantage for the way py2exe packages your application versus the way that packpanda does it; it’s all still running the same interpreted Python code that you run when you run it directly via python.

David

Hy fellows

Thanks for this information. I was thinking py2exe turn python in C++, i never imagine that not. I don’t guess python/panda was lazy, i just make some experiences :laughing:

If i’ve no gain in py2exe then i pack in pandapack :smiley:
Thanx Again