python-3.x - ImportError:没有名为 '_tkinter' 的模块,请安装 python3-tk 包

标签 python-3.x matplotlib tkinter ubuntu-16.04 importerror

我已经解决了这方面的所有类似问题,并尝试了那里提出的解决方案。但我无法通过我的 python3-tk 解决此错误。软件包安装在我用于项目的正确 virtualenv 中。

虽然在我的项目中,我不使用 tkinter,但当我尝试运行文件时,我收到以下与 _tkinter 相关的错误模块。

Traceback (most recent call last):
File "/usr/lib/python3.5/tkinter/init.py", line 36, in import _tkinter
ImportError: No module named '_tkinter'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/manuelanayantarajeyaraj/PycharmProjects/ChatbotWord2Vec/main.py", line 2, in from matplotlib import pyplot as plt
File "/home/manuelanayantarajeyaraj/usr/myProject/my_project/lib/python3.5/site-packages/matplotlib/pyplot.py", line 115, in _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/home/manuelanayantarajeyaraj/usr/myProject/my_project/lib/python3.5/site-packages/matplotlib/backends/init.py", line 62, in pylab_setup [backend_name], 0)
File "/home/manuelanayantarajeyaraj/usr/myProject/my_project/lib/python3.5/site-packages/matplotlib/backends/backend_tkagg.py", line 4, in from . import tkagg # Paint image to Tk photo blitter extension.
File "/home/manuelanayantarajeyaraj/usr/myProject/my_project/lib/python3.5/site-packages/matplotlib/backends/tkagg.py", line 5, in from six.moves import tkinter as Tk
File "/home/manuelanayantarajeyaraj/usr/myProject/my_project/lib/python3.5/site-packages/six.py", line 92, in get result = self._resolve()
File "/home/manuelanayantarajeyaraj/usr/myProject/my_project/lib/python3.5/site-packages/six.py", line 115, in _resolve return _import_module(self.mod)
File "/home/manuelanayantarajeyaraj/usr/myProject/my_project/lib/python3.5/site-packages/six.py", line 82, in _import_module import(name)
File "/usr/lib/python3.5/tkinter/init.py", line 38, in raise ImportError(str(msg) + ', please install the python3-tk package')
ImportError: No module named '_tkinter', please install the python3-tk package



因此,我导航到我的解释器的位置并创建了一个 virtualenv 并安装了 python3-tk使用以下包
sudo apt-get install python3-tk

当我检查时,所有的包似乎都是最新的
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-tk is already the newest version (3.6.5-3~16.04.york0.2).
The following packages were automatically installed and are no longer required:
  libappindicator1 libindicator7 libllvm4.0 linux-headers-4.10.0-28
  linux-headers-4.10.0-28-generic linux-headers-4.13.0-36
  linux-headers-4.13.0-36-generic linux-headers-4.13.0-37
  linux-headers-4.13.0-37-generic linux-image-4.10.0-28-generic
  linux-image-4.13.0-36-generic linux-image-4.13.0-37-generic
  linux-image-extra-4.10.0-28-generic linux-image-extra-4.13.0-36-generic
  linux-image-extra-4.13.0-37-generic linux-signed-image-4.10.0-28-generic
  linux-signed-image-4.13.0-36-generic linux-signed-image-4.13.0-37-generic
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 37 not upgraded.

但我仍然收到相同的导入错误 ImportError: No module named '_tkinter', please install the python3-tk package .

在这方面的任何建议都将受到高度赞赏。

最佳答案

该消息表明当您运行 sudo apt-get install python3-tk它告诉你 tkinter 被安装为 Python3.6.5 ,但另一方面,ImportError 相关Python3.5 .所以我相信这应该可以解决您的问题:

sudo apt-get install python3.5-tk

关于python-3.x - ImportError:没有名为 '_tkinter' 的模块,请安装 python3-tk 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50327906/

相关文章:

python - 使用python在打开的cv中使用鼠标事件绘制矩形或线

python - 从 shell 环境分析 Python 脚本

python - Pandas 箱线图中共享轴的不同 ylim

python - matplotlib 上限反转

python - 注册用户名和密码

python - 由 tkinter 的 .grid() 方法设置的小部件之间的填充,即使我没有设置它

python - Tkinter Treeview 如何用鼠标正确选择多个项目

python-3.x - 错误 : No module named Elasticsearch

python - NoReverseMatch 与关键字参数 uidb64 与 Django 2.0

Python 2.7 NetworkX(使其具有交互性)