当我运行以下代码时:
import Tkinter
我收到此错误消息:
>>> 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
然而,安装了python-tk。
$ 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.
调查为什么会失败,我看了Tkinter.py。这是失败的一条线。
try:
import _tkinter
except ImportError, msg:
raise ImportError, str(msg) + ', please install the python-tk package'
这是路径问题吗?任何帮助将不胜感激。
答案 0 :(得分:2)
似乎图书馆已损坏。尝试sudo apt-get remove python-tk
,然后sudo apt-get clean
,以便重新下载软件包sudo apt-get install python-tk
,然后再次尝试导入。另一种可能性是你以某种方式搞砸了你的apt / sources.list,你已经安装了一个适用于错误平台的库。
如果在尝试上述操作后仍无法正常工作,请对此答案发表评论。
答案 1 :(得分:1)
我不确定问题是什么,但已经解决了。 我的VM在VMware Player更新期间损坏,因此我不得不重新安装。在全新安装之后,事情正在发挥作用。谢谢你的帮助。