我电脑上的pyglet模块无法正常工作。我已经尝试了很多其他人的建议,但没有一个有效。
首先我尝试了pip3 install pyglet。但是当我尝试运行代码时出现了这个错误:
Traceback (most recent call last):
File "/Users/chervjay/Downloads/gameloop.py", line 5, in <module>
from pyglet.gl import *
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pyglet/gl/__init__.py", line 236, in <module>
import pyglet.window
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pyglet/window/__init__.py", line 1816, in <module>
gl._create_shadow_window()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pyglet/gl/__init__.py", line 205, in _create_shadow_window
_shadow_window = Window(width=1, height=1, visible=False)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pyglet/window/__init__.py", line 493, in __init__
display = get_platform().get_default_display()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pyglet/window/__init__.py", line 1765, in get_default_display
return pyglet.canvas.get_display()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pyglet/canvas/__init__.py", line 82, in get_display
return Display()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pyglet/canvas/carbon.py", line 22, in __init__
import MacOS
ImportError: No module named 'MacOS'
然后我注释掉了在carbon.py中使用MacOS的行,它们只有2行,并再次运行,这次它说
Traceback (most recent call last):
File "/Users/chervjay/Downloads/gameloop.py", line 132, in <module>
app = App()
File "/Users/chervjay/Downloads/gameloop.py", line 114, in __init__
self.hud = Hud(self.win)
File "/Users/chervjay/Downloads/gameloop.py", line 97, in __init__
color=(1, 1, 1, 0.5),
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pyglet/font/__init__.py", line 348, in __init__
group=self._group)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pyglet/text/layout.py", line 791, in __init__
self.document = document
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pyglet/text/layout.py", line 874, in _set_document
self._init_document()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pyglet/text/layout.py", line 977, in _init_document
self._update()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pyglet/text/layout.py", line 911, in _update
lines = self._get_lines()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pyglet/text/layout.py", line 887, in _get_lines
glyphs = self._get_glyphs()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pyglet/text/layout.py", line 1016, in _get_glyphs
glyphs.extend(font.get_glyphs(text[start:end]))
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pyglet/font/base.py", line 378, in get_glyphs
self.glyphs[c] = glyph_renderer.render(c)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pyglet/font/carbon.py", line 240, in render
text_ucs2 = str_ucs2(text)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pyglet/font/carbon.py", line 194, in str_ucs2
return create_string_buffer(text + '\0')
TypeError: can't concat bytes to str
我试过了
pip3.5 install --upgrade http://pyglet.googlecode.com/archive/tip.zip
并得到了同样的错误。我找不到任何其他答案。
如果你知道如何,请帮忙。谢谢。
我收到的代码是我试图从http://tartley.com/?p=250开始运行。