我在CentOS 6.5中安装了python 2.7.10。然后我用pip安装了matplotlib。但是,我在尝试导入matplotlib.pyplot时收到以下错误。
import matplotlib.pyplot
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 115, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 6, in <module>
from six.moves import tkinter as Tk
File "/usr/local/lib/python2.7/site-packages/six.py", line 203, in load_module
mod = mod._resolve()
File "/usr/local/lib/python2.7/site-packages/six.py", line 115, in _resolve
return _import_module(self.mod)
File "/usr/local/lib/python2.7/site-packages/six.py", line 82, in _import_module
__import__(name)
File "/usr/local/lib/python2.7/lib-tk/Tkinter.py", line 39, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
似乎已经安装了tkinter
“已安装软件包tkinter-2.6.6-66.el6_8.x86_64和最新版本”
我在python2.6 / lib-dynload中有_tkinter.so模块,但在python2.7 / lib-dynload下没有任何与tkinter相关的内容。
/usr/lib64/python2.6/lib-dynload/_tkinter.so
/usr/local/lib/python2.7/lib-tk/test/test_tkinter
另外,我在python中验证了sys.path以获得以下内容:
Python 2.7.10 (default, Jun 1 2017, 18:51:46)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print '\n'.join(sys.path)
/usr/local/lib/python27.zip
/usr/local/lib/python2.7
/usr/local/lib/python2.7/plat-linux2
/usr/local/lib/python2.7/lib-tk
/usr/local/lib/python2.7/lib-old
/usr/local/lib/python2.7/lib-dynload
/usr/local/lib/python2.7/site-packages
答案 0 :(得分:0)
这可能是您的python库路径的问题。检查安装 tkinter的位置,并确保您的Python解释器可以使用它。你能从tkinter
进口其他任何东西吗?
答案 1 :(得分:0)
尝试安装tkinter,因为他们说“没有名为_tkinter的模块”。 您可以使用该命令执行此操作:
sudo apt-get install python-tk