PyOpenGL 在使用 cx_Freeze 冻结后引发异常?
PyOpenGL raises an exception after being frozen using cx_Freeze?
我正在 PyOpenGL 中制作游戏并想使用 cx_Freeze 冻结它。但在我看来,导入 PyOpenGL 会在 PyOpenGL 模块中引发异常。
from OpenGL.GL import *
当我运行冻结脚本时:
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
如何解决这个问题并让 PyOpenGL 工作?
编辑:
对于没有 PyOpenGL 的人,下面的函数显示了它是如何工作的:
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()
还有平台插件功能:
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,))
尝试将 "OpenGL"
添加到 setup.py
脚本中 build_exe_options
的 packages
列表中:
build_exe_options = {"packages": ["OpenGL"]}
# ...
setup( name = ..., # complete!
...
options = {"build_exe": build_exe_options},
executables = [Executable(...)])
有关详细信息,请参阅 cx_Freeze documentation。
我正在 PyOpenGL 中制作游戏并想使用 cx_Freeze 冻结它。但在我看来,导入 PyOpenGL 会在 PyOpenGL 模块中引发异常。
from OpenGL.GL import *
当我运行冻结脚本时:
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
如何解决这个问题并让 PyOpenGL 工作?
编辑: 对于没有 PyOpenGL 的人,下面的函数显示了它是如何工作的:
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()
还有平台插件功能:
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,))
尝试将 "OpenGL"
添加到 setup.py
脚本中 build_exe_options
的 packages
列表中:
build_exe_options = {"packages": ["OpenGL"]}
# ...
setup( name = ..., # complete!
...
options = {"build_exe": build_exe_options},
executables = [Executable(...)])
有关详细信息,请参阅 cx_Freeze documentation。