Python3 和 Pyglet - 需要帮助
Python3 and Pyglet - help needed
我是 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)
知道原因的请帮忙看看。谢谢
正如我们从上面的评论中发现的那样,看起来安装输出打印了一些奇怪的符号。那以及 pyglet 在加载 UTF-8 上下文时遇到问题这一事实让我相信 OS.
中没有生成 UTF-8 支持
通常,您可以在 /etc/locale.conf
和 运行 locale-gen
中取消注释 en_US.UTF-8
,这应该可以解决问题。
- 编辑您的
/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
- 重启
在您的终端中
- 写
LANG=en_US
- 运行 来自终端的 python 代码
另一种解决方案,将其放在代码的所有内容之前
import os
os.environ['LANG']='en_US'
我是 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)
知道原因的请帮忙看看。谢谢
正如我们从上面的评论中发现的那样,看起来安装输出打印了一些奇怪的符号。那以及 pyglet 在加载 UTF-8 上下文时遇到问题这一事实让我相信 OS.
中没有生成 UTF-8 支持通常,您可以在 /etc/locale.conf
和 运行 locale-gen
中取消注释 en_US.UTF-8
,这应该可以解决问题。
- 编辑您的
/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
- 重启
在您的终端中
- 写
LANG=en_US
- 运行 来自终端的 python 代码
另一种解决方案,将其放在代码的所有内容之前
import os
os.environ['LANG']='en_US'