我正在尝试使用Python库pyglet为精灵加载图像。最初的目的是与游戏相关的,但我相信我已将问题简化为一行代码。在Python Shell中,我导入pyglet,然后运行以下代码行(或等效代码):

pyglet.image.load("image.png")

Python退出,终端输出:
Segmentation fault (core dumped)

有时候,它不这样做,而是抛出
Traceback (most recent call last):
  File "/usr/lib/python3.4/site-packages/pyglet/__init__.py", line 351, in __getattr__
    return getattr(self._module, name)
AttributeError: 'NoneType' object has no attribute 'load'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.4/site-packages/pyglet/__init__.py", line 357, in __getattr__
    __import__(import_name)
  File "/usr/lib/python3.4/site-packages/pyglet/image/__init__.py", line 145, in <module>
    from pyglet.gl import *
  File "/usr/lib/python3.4/site-packages/pyglet/gl/__init__.py", line 236, in <module>
    import pyglet.window
  File "/usr/lib/python3.4/site-packages/pyglet/window/__init__.py", line 1816, in <module>
    gl._create_shadow_window()
  File "/usr/lib/python3.4/site-packages/pyglet/gl/__init__.py", line 205, in _create_shadow_window
    _shadow_window = Window(width=1, height=1, visible=False)
  File "/usr/lib/python3.4/site-packages/pyglet/window/xlib/__init__.py", line 166, in __init__
    super(XlibWindow, self).__init__(*args, **kwargs)
  File "/usr/lib/python3.4/site-packages/pyglet/window/__init__.py", line 515, in __init__
    context = config.create_context(gl.current_context)
  File "/usr/lib/python3.4/site-packages/pyglet/gl/xlib.py", line 186, in create_context
    return XlibContextARB(self, share)
  File "/usr/lib/python3.4/site-packages/pyglet/gl/xlib.py", line 300, in __init__
    super(XlibContext13, self).__init__(config, share)
  File "/usr/lib/python3.4/site-packages/pyglet/gl/xlib.py", line 203, in __init__
    raise gl.ContextException('Could not create GL context')
pyglet.gl.ContextException: Could not create GL context

要么
Traceback (most recent call last):
  File "/usr/lib/python3.4/site-packages/pyglet/__init__.py", line 351, in __getattr__
    return getattr(self._module, name)
AttributeError: 'NoneType' object has no attribute 'load'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.4/site-packages/pyglet/__init__.py", line 357, in __getattr__
    __import__(import_name)
  File "/usr/lib/python3.4/site-packages/pyglet/image/__init__.py", line 145, in <module>
    from pyglet.gl import *
  File "/usr/lib/python3.4/site-packages/pyglet/gl/__init__.py", line 101, in <module>
    from pyglet.gl import gl_info
ImportError: cannot import name 'gl_info'

(我不确定为什么它会在这两者之间交替出现。)

此外,
pyglet.window.Window()

也抛出异常
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.4/site-packages/pyglet/window/xlib/__init__.py", line 166, in __init__
    super(XlibWindow, self).__init__(*args, **kwargs)
  File "/usr/lib/python3.4/site-packages/pyglet/window/__init__.py", line 515, in __init__
    context = config.create_context(gl.current_context)
  File "/usr/lib/python3.4/site-packages/pyglet/gl/xlib.py", line 186, in create_context
    return XlibContextARB(self, share)
  File "/usr/lib/python3.4/site-packages/pyglet/gl/xlib.py", line 300, in __init__
    super(XlibContext13, self).__init__(config, share)
  File "/usr/lib/python3.4/site-packages/pyglet/gl/xlib.py", line 203, in __init__
    raise gl.ContextException('Could not create GL context')
pyglet.gl.ContextException: Could not create GL context

从 shell 运行时。有时,它在从文件运行时会运行(它将运行,在随后的运行中失败,然后最终可以再次运行),如果我没记错的话,它在运行cx_Freeze冻结的Python程序中也没有问题。

在Google上,我没有找到比几年前新的东西。我对OpenGL了解不多;目前,我使用pyglet是因为它可以简化构建应用程序的方式。

我正在运行带有XFCE,AMD CPU和AMD集成显卡(带有封闭的Catalyst驱动程序)的64位Manjaro Linux。我有Python 3.4.2和pyglet 1.2.0。

有任何想法吗?

最佳答案

现在(2016.10.30),此问题已修复。在网站开发中有关它的当前报告。

Pyglet网站开发人员是图像加载器的一个示例:http://www.pyglet.org/doc/programming_guide/image_viewer.html

在我的Archlinux系统中(Linux alw 3.19.1-1-ARCH#1 SMP PREEMPT Sat Mar 7 20 7:59:30 CET 2015 x86_64 GNU/Linux),该错误仍然存​​在-内核与python-3一起丢弃,bat与python-2。我使用的是pyglet的最新版本-1.2.2。

在MS-Win 8.1上,此示例可以正常运行。我认为问题在于此模块的工作不正确。

在开发站点https://bitbucket.org/pyglet/pyglet/issue/25/core-dumped-on-linux-64上已报告有关此错误的信息

现在您只能使用PNG格式:

...
from pyglet.image.codecs.png import PNGImageDecoder

fname = 'pennant.png'
img_pennant = pyglet.image.load(fname, decoder=PNGImageDecoder())
...

此代码未核心转储。

关于python - pyglet分割错误和其他错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28638616/

10-11 18:18