Python3和Pyglet-需要帮助

问题描述 投票:0回答:3

我是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)

如果您知道原因,请提供帮助。谢谢。

python python-3.x pyglet
3个回答
1
投票

正如我们从上面的注释中发现的那样,安装输出看起来像打印了一些奇数符号。 pyglet在加载UTF-8上下文时遇到问题,这一事实使我相信操作系统中没有生成UTF-8支持。

通常,您可以在en_US.UTF-8中取消注释/etc/locale.conf并运行locale-gen,这应该可以解决问题。


0
投票
  1. 编辑您的/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
  1. 使用sudo dpkg-reconfigure locales设置您自己的语言。确保标记en_US.UTF-8选择。
  2. sudo locale-gen en_US en_US.UTF-8
  3. 重新启动

0
投票

在您的终端中

  1. LANG=en_US
  2. 从终端运行python代码

另一种解决方案,将其放置在代码的所有内容之前

import os
os.environ['LANG']='en_US'
© www.soinside.com 2019 - 2024. All rights reserved.