AttributeError: 'module' 对象没有属性 'maketrans' [英] AttributeError: 'module' object has no attribute 'maketrans'
问题描述
我之前一直在对此错误进行一些研究.StackOverflow 中有一些相关的解释,但建议的解决方案是完全无关的.
当我尝试从 gi.repository 导入 Gtk 时,它崩溃并显示以下输出:<代码>
bash-4.2$ python3Python 3.2(r32:88445,2011 年 2 月 21 日,21:11:06)[GCC 4.6.0 20110212 (Red Hat 4.6.0-0.7)] 在 linux2输入帮助"、版权"、信用"或许可"以获取更多信息.
由于这是直接从 python 控制台导入而不是通过执行 python 文件脚本,我什至不知道如何处理这个.
好的,我设法让它工作了.尽管是一个肮脏的解决方法:
我修改了/usr/lib64/python3.2/site-packages/gi/module.py
在第 127 行中,我将 string.maketrans
替换为 str.maketrans
,因此它符合 python 3 文档.
希望对我情况下的任何人有所帮助.
雨果
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.
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
这篇关于AttributeError: 'module' 对象没有属性 'maketrans'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!