gpt4 book ai didi

python - PyOpenGL 在使用 cx_Freeze 卡住后引发异常?

转载 作者:太空宇宙 更新时间:2023-11-03 23:58:14 26 4
gpt4 key购买 nike

我正在 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_optionspackages 列表中:

build_exe_options = {"packages": ["OpenGL"]}

# ...

setup( name = ..., # complete!
...
options = {"build_exe": build_exe_options},
executables = [Executable(...)])

参见 cx_Freeze documentation了解更多详情。

关于python - PyOpenGL 在使用 cx_Freeze 卡住后引发异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56753878/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com