Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
630 views
in Technique[技术] by (71.8m points)

python 3.x - AttributeError: 'module' object has no attribute 'maketrans'

I've been doing some previous research about this error. There are some explanations here in StackOverflow related, the solutions suggested are quite unrelated though.

When I try to import Gtk from gi.repository, it crashes with the following output:
bash-4.2$ python3 Python 3.2 (r32:88445, Feb 21 2011, 21:11:06) [GCC 4.6.0 20110212 (Red Hat 4.6.0-0.7)] on linux2 Type "help", "copyright", "credits" or "license" for more information.

>>> from gi.repository import Gtk

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python3.2/site-packages/gi/importer.py", line 76, in load_module  
dynamic_module._load()
File "/usr/lib64/python3.2/site-packages/gi/module.py", line 251, in _load
overrides_modules = __import__('gi.overrides', fromlist=[self._namespace])
File "/usr/lib64/python3.2/site-packages/gi/overrides/Gtk.py", line 400, in <module>
class MessageDialog(Gtk.MessageDialog, Dialog):
File "/usr/lib64/python3.2/site-packages/gi/overrides/Gtk.py", line 404, in   
MessageDialog
type=Gtk.MessageType.INFO,
File "/usr/lib64/python3.2/site-packages/gi/module.py", line 127, in __getattr__
ascii_upper_trans = string.maketrans(
AttributeError: 'module' object has no attribute 'maketrans' 

Since this is an import straight from python console and not by executing a python file script I don't even have a clue how to handle this.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Ok, I managed to get it work. Despite is a dirty workaround:

I modified /usr/lib64/python3.2/site-packages/gi/module.py

in line 127 I replaced string.maketrans with str.maketrans so it complies with python 3 docs.

Hope to be helpful for anyone in my circumstances.

Hugo


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...