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.
JavaScript
x
2
1
from OpenGL.GL import *
2
When I run the frozen script:
JavaScript
1
17
17
1
Traceback (most recent call last):
2
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/cx_Freeze/initscripts/__startup__.py", line 14, in run
3
module.run()
4
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/cx_Freeze/initscripts/Console.py", line 26, in run
5
exec(code, m.__dict__)
6
File "/Users/noah/Desktop/DesktopNoah/cx_freeze/PhW.py", line 5, in <module>
7
from OpenGL.GL import *
8
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/OpenGL/GL/__init__.py", line 3, in <module>
9
from OpenGL import error as _error
10
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/OpenGL/error.py", line 12, in <module>
11
from OpenGL import platform, _configflags
12
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/OpenGL/platform/__init__.py", line 35, in <module>
13
_load()
14
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/OpenGL/platform/__init__.py", line 29, in _load
15
plugin = plugin_class()
16
TypeError: 'NoneType' object is not callable
17
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:
JavaScript
1
17
17
1
import os, sys
2
from OpenGL.plugins import PlatformPlugin
3
def _load( ):
4
"""Load the os.name plugin for the platform functionality"""
5
key = (os.environ.get( 'PYOPENGL_PLATFORM'), sys.platform,os.name)
6
plugin = PlatformPlugin.match( key )
7
plugin_class = plugin.load()
8
plugin.loaded = True
9
# create instance of this platform implementation
10
plugin = plugin_class()
11
12
# install into the platform module's namespace now
13
plugin.install(globals())
14
return plugin
15
16
_load()
17
And also the platform plugin function:
JavaScript
1
16
16
1
class PlatformPlugin( Plugin ):
2
"""Platform-level plugin registration"""
3
registry = []
4
@classmethod
5
def match( cls, key ):
6
"""Determine what platform module to load
7
8
key -- (sys.platform,os.name) key to load
9
"""
10
for possible in key:
11
# prefer sys.platform, *then* os.name
12
for plugin in cls.registry:
13
if plugin.name == possible:
14
return plugin
15
raise KeyError( """No platform plugin registered for %s"""%(key,))
16
Advertisement
Answer
Try to add "OpenGL"
to the packages
list of the build_exe_options
in the setup.py
script:
JavaScript
1
9
1
build_exe_options = {"packages": ["OpenGL"]}
2
3
# ...
4
5
setup( name = , # complete!
6
7
options = {"build_exe": build_exe_options},
8
executables = [Executable( )])
9
See the cx_Freeze documentation for further details.