Python3 and Pyglet - help needed

3.5k views Asked by At

I am a newbie of Python and Pyglet. I just installed Pyglet on my Linux and Window7. I run a very simple test file on my Linux, I got errors

(On linux: Python 3.5.2 Pyglet 1.2.4)

The following is the test file-tests.py:

import pyglet

window = pyglet.window.Window()
pyglet.app.run()

I got the following errors when I run it on my 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*

This test file works ok on my Win7

(On Window7: Python 3.6.0 Pyglet 1.2.4)

Please help if you know why. Thanks.

3

There are 3 answers

0
Torxed On BEST ANSWER

As we figured out from the comments above, it looked like the installation output printed some odd symbols. That and the fact that pyglet had problem loading UTF-8 context lead me to believe that there were no UTF-8 support generated in the OS.

Usually, you can uncomment en_US.UTF-8 in /etc/locale.conf and run locale-gen and that should solve the problem.

2
ujjal das On

in your terminal

  1. write LANG=en_US
  2. Run your python code from the terminal

another solution by placing it before everything of your code

import os
os.environ['LANG']='en_US'
0
Stayermax On
  1. edit your /etc/default/locale, and try to feed all locale critiria as the same:
#  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. Use sudo dpkg-reconfigure locales to set your own language. Make sure to mark en_US.UTF-8 selection.
  2. sudo locale-gen en_US en_US.UTF-8
  3. Reboot