Got py2exe + PyOpenGL limping across the line... (Need to add the .egg files to the path)
Last update on .
Blake was good enough to prod me abound getting PyOpenGL 3.x to run under py2exe'd applications. The problem is that even if you copy the .egg directory to the distribution directory the setuptools entry points don't get registered, so PyOpenGL can't find its array-handling mechanisms.
After lots of trial and error I just wound up adding "import pdb; pdb.set_trace()" to the script and playing with it until I found something that let me load up the OpenGL hierarchy.
As it turns out, all that's necessary is to add the .egg directories to sys.path (I spent hours trying to figure out where setuptools registers its handlers). In regular installations that registration is done by the easy_install.pth directory processed by the site.py script. .pth files aren't supported under py2exe, however, so you have to roll your own support when building a stand-along application.
To hack the proof-of-concept I just created a "site.py" module in the distribution directory that adds the PyOpenGL-3.0.0a5-py2.5.egg directory to the path. Importing OpenGL after an "import site" then results in a functional demo. The proper fix is probably having py2exe or py2app notice the presence of the eggs and copy them over; then at run-time it could scan the distribution directory for all .egg files and add them to the path.
Comments are closed.
Pingbacks are closed.
Lutz Paelike on 02/06/2007 8:16 a.m. #
I had the same problems to make eggs work in special environments and also to be loaded properly from a standalone exe. What i do is to include pkg_resources into the exe and then use an Evironment object to process the eggs:<br />
import pkg_resources as p<br />
# use an Environment object with a custom search path<br />
env = p.Environment(['.','modules','plugins'])<br />
for dists in env:<br />
...pkgs = env[dists]<br />
...# only activate the newest distribution available<br />
...dist = pkgs.pop(0)<br />
...print "activating ", dist<br />
After the eggs are activated entry points can be discovered...<br />
for entrypoint in p.iter_entry_points("my.plugins"):<br />
...plugin_class = entrypoint.load()<br />
By the way whitespace is stripped in your comment form therefore i used the leading dots.<br />
Mike Fletcher on 02/06/2007 4:50 p.m. #
Thanks Lutz, that's exactly the kind of thing I was looking for. I've put it into a <a href="http://pyopengl.cvs.sourceforge.net/pyopengl/OpenGL-ctypes/src/py2exeeggs.py?view=markup">little module for import</a>. Guess I should see if py2exe people are interested in it too.
Mike Fletcher on 02/06/2007 10:03 p.m. #
I discovered that the code as given doesn't work with mixed-case eggs, as the pkg_resources call is using normcase under the covers. Will have to work around that.
Lutz Paelike on 02/07/2007 9:42 a.m. #
Hey Mike,<br />
nice to see that this is useful for you.<br />
I can not confirm the problems you have with mixed-case named eggs, though.<br />
As long as the files are named *.egg and they are valid eggs (they contain complete metadata especially EGG-INFO/PKG_INFO and such) they are correctly found.<br />
I had some problems in the building process which lead to missing metadata in the egg. Maybe this is your problem?<br />
Cheers, <br />