我正在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,))
答案 0 :(得分:3)
尝试在{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"keyofStringsOnly": true,
"baseUrl": "./",
"paths": {
"@src/*": [
"src/*"
],
"react": [
"node_modules/@types/*"
]
},
"outDir": "build/dist",
"lib": [
"es7",
"dom"
],
"types": ["markerclustererplus", "react", "googlemaps", "node"],
"typeRoots": [
"src/typings",
"node_modules/@types"
],
},
"exclude": [
...
]
}
脚本中将"OpenGL"
添加到packages
的{{1}}列表中:
build_exe_options
有关更多详细信息,请参见cx_Freeze documentation。