Gym: when call render() function, it say:XlibException: Could not create UTF8 text property

Created on 31 Jul 2017  路  13Comments  路  Source: openai/gym

Hello, i want to ask a question, not matter what env i initial, when i call render() function, it say:

File "/home/hit/anaconda2/envs/py3k/lib/python3.6/site-packages/gym/core.py", line 150, in render
return self._render(mode=mode, close=close)

File "/home/hit/anaconda2/envs/py3k/lib/python3.6/site-packages/gym/core.py", line 286, in _render
return self.env.render(mode, close)

File "/home/hit/anaconda2/envs/py3k/lib/python3.6/site-packages/gym/core.py", line 150, in render
return self._render(mode=mode, close=close)

File "/home/hit/anaconda2/envs/py3k/lib/python3.6/site-packages/gym/envs/classic_control/cartpole.py", line 115, in _render
from gym.envs.classic_control import rendering

File "/home/hit/anaconda2/envs/py3k/lib/python3.6/site-packages/gym/envs/classic_control/rendering.py", line 23, in
from pyglet.gl import *

File "/home/hit/anaconda2/envs/py3k/lib/python3.6/site-packages/pyglet/gl/__init__.py", line 236, in
import pyglet.window

File "/home/hit/anaconda2/envs/py3k/lib/python3.6/site-packages/pyglet/window/__init__.py", line 1816, in
gl._create_shadow_window()

File "/home/hit/anaconda2/envs/py3k/lib/python3.6/site-packages/pyglet/gl/__init__.py", line 205, in _create_shadow_window
_shadow_window = Window(width=1, height=1, visible=False)

File "/home/hit/anaconda2/envs/py3k/lib/python3.6/site-packages/pyglet/window/xlib/__init__.py", line 163, in __init__
super(XlibWindow, self).__init__(args, *kwargs)

File "/home/hit/anaconda2/envs/py3k/lib/python3.6/site-packages/pyglet/window/__init__.py", line 558, in __init__
self._create()

File "/home/hit/anaconda2/envs/py3k/lib/python3.6/site-packages/pyglet/window/xlib/__init__.py", line 353, in _create
self.set_caption(self._caption)

File "/home/hit/anaconda2/envs/py3k/lib/python3.6/site-packages/pyglet/window/xlib/__init__.py", line 513, in set_caption
self._set_text_property('_NET_WM_NAME', caption)

File "/home/hit/anaconda2/envs/py3k/lib/python3.6/site-packages/pyglet/window/xlib/__init__.py", line 783, in _set_text_property
raise XlibException('Could not create UTF8 text property')

XlibException: Could not create UTF8 text property

can you help me, thanks

Most helpful comment

Simpler solution:

In your terminal window:

  1. Write LANG=en_US
  2. Run your python code
    It worked for me. You will need to do this every time you open a new terminal.

Another option:
Add the following to your python code (before everything):

import os
os.environ['LANG']='en_US'

All 13 comments

I got the same problem.

Same issue

Python2.7 has no such issue.

same problem
anybody fixed this somehow?

Any fixes?

same problem for python 3.5

pygame environment also has this problem for python 3.5

import pyglet
window = pyglet.window.Window()

Even though the developer claim that it's the problem of locale.
However, the program can run normally in python 2.7, while failing in python 3.5.
Thus I think it's the problem of pyglet.
I try for the above code,
and the error will occur.

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/pyglet/__init__.py", line 378, 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 "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/pyglet/__init__.py", line 384, in __getattr__
    __import__(import_name)
  File "/usr/local/lib/python3.5/dist-packages/pyglet/window/__init__.py", line 1884, in <module>
    gl._create_shadow_window()
  File "/usr/local/lib/python3.5/dist-packages/pyglet/gl/__init__.py", line 208, in _create_shadow_window
    _shadow_window = Window(width=1, height=1, visible=False)
  File "/usr/local/lib/python3.5/dist-packages/pyglet/window/xlib/__init__.py", line 166, in __init__
    super(XlibWindow, self).__init__(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/pyglet/window/__init__.py", line 571, in __init__
    self._create()
  File "/usr/local/lib/python3.5/dist-packages/pyglet/window/xlib/__init__.py", line 356, in _create
    self.set_caption(self._caption)
  File "/usr/local/lib/python3.5/dist-packages/pyglet/window/xlib/__init__.py", line 522, in set_caption
    self._set_text_property('_NET_WM_NAME', caption)
  File "/usr/local/lib/python3.5/dist-packages/pyglet/window/xlib/__init__.py", line 806, in _set_text_property
    raise XlibException('Could not create UTF8 text property')
pyglet.window.xlib.XlibException: Could not create UTF8 text property

I refer to others opinion.
Maybe try to revise the locale setting can solve the problem.
However, I try for the following commands,
I don't know how to revise en_US.utf8 into en_US.utf-8.

$ sudo cat /etc/default/locale 
#  File generated by update-locale
LANG=en_US.UTF-8
LC_NUMERIC="lzh_TW"
LC_TIME="lzh_TW"
LC_MONETARY="lzh_TW"
LC_PAPER="lzh_TW"
LC_NAME="lzh_TW"
LC_ADDRESS="lzh_TW"
LC_TELEPHONE="lzh_TW"
LC_MEASUREMENT="lzh_TW"
LC_IDENTIFICATION="lzh_TW"

$ sudo locale -a
C
C.UTF-8
en_AG
en_AG.utf8
en_AU.utf8
en_BW.utf8
en_CA.utf8
en_DK.utf8
en_GB.utf8
en_HK.utf8
en_IE.utf8
en_IN
en_IN.utf8
en_NG
en_NG.utf8
en_NZ.utf8
en_PH.utf8
en_SG.utf8
en_US.utf8
en_ZA.utf8
en_ZM
en_ZM.utf8
en_ZW.utf8
lzh_TW
lzh_TW.utf8
POSIX

The only possible way is just using python 2.7 to run.
Does anyone have other idea?

I found an awkward solution:

  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

@SunnerLi bravo! It works for me. Thank you

Alternative solution on Ubuntu 16.04:

  1. Create the file /etc/locale.conf if not exists and insert the line LANG=en_US.UTF-8;
  2. Edit the file /etc/default/locale and let the first line be LANG=en_US.UTF-8;
  3. Run locale-gen;
  4. Reboot.

Simpler solution:

In your terminal window:

  1. Write LANG=en_US
  2. Run your python code
    It worked for me. You will need to do this every time you open a new terminal.

Another option:
Add the following to your python code (before everything):

import os
os.environ['LANG']='en_US'

Thanks for answering this @SunnerLi and @tengerye. Some applications seem to require running locale-gen en_US.UTF-8 or one of these other solutions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Gawne picture Gawne  路  4Comments

Baichenjia picture Baichenjia  路  3Comments

RuofanKong picture RuofanKong  路  3Comments

cpatyn picture cpatyn  路  4Comments

zhan0903 picture zhan0903  路  4Comments