May 16, 2009

PyOpenGL 3.0 with py2exe

One of the major hindrances to using PyOpenGL before 3.0 was released (not python 3.0) was that packaging it with py2exe was next to impossible. Thankfully with the release of PyOpenGL 3.0 it is easy. Just include these two imports in one of your project files:

from ctypes import util
try:
from OpenGL.platform import win32
except AttributeError:
pass

That will tell py2exe which part of PyOpenGL to include. Otherwise you have to copy them over manually. Be sure to have the try and except around all win32 imports so your program remains cross platform.

3 comments:

  1. Thanks for the post, but this doesn't work for me. :-( I still get a traceback on running the executable that ends as follows. I'm on WinXP, Python2.7, PyOpenGL3.0.1, py2exe 0.6.9.

    I also tried copying my site-packages\opengl\platform\* into my dist\library.zip\opengl\platform, as suggested elsewhere, but to no avail.

    Any ideas much appreciated.


    File "OpenGL\arrays\arraydatatype.pyc", line 52, in __call__
    TypeError: ("No array-type handler for type (value: <__main__.c_float_Array_6 object at 0x01EC4C60>) registered", )

    ReplyDelete
  2. @Tartley It might be because you are using python 2.7 - it's a wild guess but crazier things have happened when working with py2exe.

    I would try using python 2.5 (recommended by pygame).

    Also make sure your OpenGL imports are being picked up by py2exe.

    ReplyDelete