I recently posted a request for help with freezing PyOpenGL programs with
cx_Freeze.
With the help from Dan Helfman and Mike C Fletcher, I was able to freeze my
PyOpenGL program with py2exe.
I have not tried this with cx_Freeze, but that will probably work similarly.
I'll describe here what I did to make it work, just in case it would help
someone out there.
In order to freeze PyOpenGL applications, you need to exclude the OpenGL
library from the freeze process
and add the library manually in the distributable directory.
In order to make this work, you need to tell your application where to go
look for the OpenGL module.
To do this, you need to insert the current directory . in front of the
sys.path search list.
1) make sure you have py2exe installed
2) in your main source file, include the following at the very top (before
all the includes):
import sys
sys.path.insert( 0, '.' )
3) create a file called setup.py in your source folder with the following
content:
from distutils.core import setup
import py2exe
setup(windows=[<yourprogramhere>.py'],
options={"py2exe": {"includes": ["ctypes", "logging"],
"excludes": ["OpenGL"],
}
}
)
note: not sure about ctypes and logging. You might need more.
3) on the command line in your source folder:
python setup.py py2exe
This creates a folder called dist.
4)
Examine the output of py2exe. In my case, it put out something like:
>The following modules appear to be missing
>['OpenGL.GL', 'OpenGL.GLU', 'OpenGL.GLUT', 'OpenGL.arrays.ctypesarrays',
'OpenGL.arrays.
ctypesparameters', 'OpenGL.arrays.ctypespointers', '
>OpenGL.arrays.lists', 'OpenGL.arrays.nones', 'OpenGL.arrays.numbers',
'OpenGL.arrays.strings', 'OpenGL.platform.win32',
'OpenGL.raw.GL<http://opengl.raw.gl/>',
'du
>mmy.Process', 'email.Generator', 'email.Iterators', 'numpy']
In your main Python source file, ensure you import most of the
OpenGL-related ones.
I ommitted the funny ones like 'dummy.Process', 'email.Generator',
'email.Iterators', 'numpy'. That didn't have an impact.
In my case, I put the following imports under the "import sys" described in
point 2.
In your case, some other OpenGL related modules might appear. You might want
to import those too.
import OpenGL.platform.win32
import OpenGL.arrays.ctypesarrays
import OpenGL.arrays.ctypesparameters
import OpenGL.arrays.ctypespointers
import OpenGL.arrays.lists
import OpenGL.arrays.nones
import OpenGL.arrays.numbers
import OpenGL.arrays.strings
import OpenGL.platform.win32
import OpenGL.raw.GL
#import dummy.Process
#import email.Generator
#import email.Iterators
#import numpy
import OpenGL.GL
import OpenGL.GLU
import OpenGL.GLUT
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
if you use numpy, you need the following too:
import OpenGL.arrays.numpymodule
5)
re-run py2exe (step 3)
6)
>From C:\Python26\Lib\site-packages, copy the folder OpenGL inside the newly
created dist folder.
You can delete the pyc and pyo files to reduce the footprint
On a side note:
Pyglet programs seem to be less cumbersome to freeze. I was able to freeze
them with cx_Freeze with only one minor modification
in the Pyglet code (comment out an offending import).
According to Mike, this is because Pyglet does not support plugins, which
makes the implementation simpler.
So, in case you really can't make it work under PyOpenGL, take a look at
Pyglet.
I almost made the step until I got it working as described above
Special thanks to Mike and Dan.
Hope this helps
Jef
|