本文介绍了Python-tk 包在 Python 2.7.3 中无法识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行以下代码时:

导入Tkinter

我收到此错误消息:

>>>导入 Tkinter回溯(最近一次调用最后一次):文件<stdin>",第 1 行,位于 <module>文件/usr/lib/python2.7/lib-tk/Tkinter.py",第 42 行,在 <module> 中引发 ImportError, str(msg) + ',请安装 python-tk 包'ImportError:/usr/lib/libtk8.5.so.0: invalid ELF header, please install the python-tk package

然而,安装了python-tk.

$ sudo apt-get install python-tk阅读包裹清单...完成构建依赖树读取状态信息...完成python-tk 已经是最新版本了.0 升级,0 新安装,0 删除,0 未升级.

为了研究为什么会失败,我查看了 Tkinter.py.这是失败的线路.

尝试:导入_tkinter除了导入错误,味精:引发 ImportError, str(msg) + ',请安装 python-tk 包'

这是路径问题吗?任何帮助将不胜感激.

解决方案

似乎该库已损坏.尝试sudo apt-get remove python-tk,然后sudo apt-get clean,以便您重新下载软件包,sudo apt-get install python-tk,然后再次尝试导入.另一种可能性是您不知何故弄乱了 apt/sources.list,并且您安装了用于错误平台的库.

如果尝试上述方法后仍然无法正常工作,请对此答案发表评论.

When I run the following code:

import Tkinter

I get this error message:

>>> import Tkinter
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 42, in <module>
    raise ImportError, str(msg) + ', please install the python-tk package'
ImportError: /usr/lib/libtk8.5.so.0: invalid ELF header, please install the python-tk package

however, python-tk is installed.

$ sudo apt-get install python-tk
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-tk is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Looking into why this is failing, I looked at Tkinter.py. This is the line that is failing.

try:
    import _tkinter
except ImportError, msg:
    raise ImportError, str(msg) + ', please install the python-tk package'

Is this a path problem? Any help would be much appreciated.

解决方案

It seems like maybe that library is corrupted. Try sudo apt-get remove python-tk, then sudo apt-get clean so that you will re-download the package, sudo apt-get install python-tk, and then try importing again. Another possibility is that you've somehow got your apt/sources.list messed up, and you've installed a library that is for the wrong platform.

If it is still not working after you try the above, leave a comment on this answer.

这篇关于Python-tk 包在 Python 2.7.3 中无法识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 11:01
查看更多