I am making a game in PyOpenGL and want to freeze it using cx_Freeze. But it seems to me that importing PyOpenGL raises an exception in the PyOpenGL module.
from OpenGL.GL import *
When I run the frozen script:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/cx_Freeze/initscripts/__startup__.py", line 14, in run
module.run()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/cx_Freeze/initscripts/Console.py", line 26, in run
exec(code, m.__dict__)
File "/Users/noah/Desktop/DesktopNoah/cx_freeze/PhW.py", line 5, in <module>
from OpenGL.GL import *
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/OpenGL/GL/__init__.py", line 3, in <module>
from OpenGL import error as _error
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/OpenGL/error.py", line 12, in <module>
from OpenGL import platform, _configflags
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/OpenGL/platform/__init__.py", line 35, in <module>
_load()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/OpenGL/platform/__init__.py", line 29, in _load
plugin = plugin_class()
TypeError: 'NoneType' object is not callable
How can I solve this issue and get PyOpenGL to work?
EDIT: For people who don't have PyOpenGL, the below function shows how it is working:
import os, sys
from OpenGL.plugins import PlatformPlugin
def _load( ):
"""Load the os.name plugin for the platform functionality"""
key = (os.environ.get( 'PYOPENGL_PLATFORM'), sys.platform,os.name)
plugin = PlatformPlugin.match( key )
plugin_class = plugin.load()
plugin.loaded = True
# create instance of this platform implementation
plugin = plugin_class()
# install into the platform module's namespace now
plugin.install(globals())
return plugin
_load()
And also the platform plugin function:
class PlatformPlugin( Plugin ):
"""Platform-level plugin registration"""
registry = []
@classmethod
def match( cls, key ):
"""Determine what platform module to load
key -- (sys.platform,os.name) key to load
"""
for possible in key:
# prefer sys.platform, *then* os.name
for plugin in cls.registry:
if plugin.name == possible:
return plugin
raise KeyError( """No platform plugin registered for %s"""%(key,))
Try to add "OpenGL"
to the packages
list of the build_exe_options
in the setup.py
script:
build_exe_options = {"packages": ["OpenGL"]}
# ...
setup( name = ..., # complete!
...
options = {"build_exe": build_exe_options},
executables = [Executable(...)])
See the cx_Freeze documentation for further details.