我是Python和Pyglet的新手。我刚刚在我的Linux和Window7上安装了Pyglet。我在Linux上运行一个非常简单的测试文件,我收到了错误
(在Linux上:Python 3.5.2 Pyglet 1.2.4)
以下是测试文件--tests.py:
import pyglet
window = pyglet.window.Window()
pyglet.app.run()
我在Linux上运行时遇到以下错误:
Traceback (most recent call last):
File "/home/work/.local/lib/python3.5/site-packages/pyglet/init.py", line 351, in getattr return getattr(self._module, name)
AttributeError: 'NoneType' object has no attribute 'Window'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "test.py", line 6, in <module> window = pyglet.window.Window() File "/home/work/.local/lib/python3.5/site-packages/pyglet/init.py", line 357, in getattr import(import_name)
File "/home/work/.local/lib/python3.5/site-packages/pyglet/window/init.py", line 1816, in <module> gl._create_shadow_window()
File "/home/work/.local/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 "/home/work/.local/lib/python3.5/site-packages/pyglet/window/xlib/init.py", line 163, in init super(XlibWindow, self).init(args, *kwargs)
File "/home/work/.local/lib/python3.5/site-packages/pyglet/window/init.py", line 558, in init self._create()
File "/home/work/.local/lib/python3.5/site-packages/pyglet/window/xlib/init.py", line 353, in _create self.set_caption(self._caption)
File "/home/work/.local/lib/python3.5/site-packages/pyglet/window/xlib/init.py", line 513, in set_caption self._set_text_property('_NET_WM_NAME', caption)
File "/home/work/.local/lib/python3.5/site-packages/pyglet/window/xlib/init.py", line 783, in _set_text_property raise XlibException('Could not create UTF8 text property')
pyglet.window.xlib.XlibException: Could not create UTF8 text property*
此测试文件在我的Win7上运行正常
(在Window7:Python 3.6.0 Pyglet 1.2.4上)
如果您知道原因,请提供帮助。感谢。
答案 0 :(得分:1)
正如我们从上面的评论中看到的那样,看起来安装输出打印了一些奇怪的符号。那个以及pyglet加载UTF-8上下文有问题的事实让我相信操作系统中没有生成UTF-8支持。
通常,您可以在en_US.UTF-8
中取消注释/etc/locale.conf
并运行locale-gen
,这样可以解决问题。
答案 1 :(得分:0)
/etc/default/locale
,并尝试以相同的方式满足所有语言环境的要求:# File generated by update-locale
LANG=en_US.UTF-8
LC_NUMERIC=en_US.UTF-8
LC_TIME=en_US.UTF-8
LC_MONETARY=en_US.UTF-8
LC_PAPER=en_US.UTF-8
LC_NAME=en_US.UTF-8
LC_ADDRESS=en_US.UTF-8
LC_TELEPHONE=en_US.UTF-8
LC_MEASUREMENT=en_US.UTF-8
LC_IDENTIFICATION=en_US.UTF-8
LC_ALL=en_US.UTF-8
sudo dpkg-reconfigure locales
设置您自己的语言。确保标记en_US.UTF-8
选择。sudo locale-gen en_US en_US.UTF-8
答案 2 :(得分:0)
在您的终端
LANG=en_US
另一种解决方案,将其放置在所有代码之前
import os
os.environ['LANG']='en_US'