【发布时间】:2018-10-23 23:18:48
【问题描述】:
我已经解决了这方面的所有类似问题,并尝试了那里提出的解决方案。但是,尽管我的 python3-tk 包安装在我用于我的项目的正确 virtualenv 中,但我无法解决此错误。
虽然在我的项目中,我没有使用 tkinter,但当我尝试运行该文件时,我收到了与 _tkinter 模块相关的以下错误。
回溯(最近一次通话最后一次):
文件“/usr/lib/python3.5/tkinter/init.py”,第 36 行,在 导入 _tkinter
ImportError:没有名为“_tkinter”的模块在处理上述异常的过程中,又发生了一个异常:
回溯(最近一次通话最后一次):
文件“/home/manuelanayantarajeyaraj/PycharmProjects/ChatbotWord2Vec/main.py”,第 2 行,在 从 matplotlib 导入 pyplot 作为 plt
文件“/home/manuelanayantarajeyaraj/usr/myProject/my_project/lib/python3.5/site-packages/matplotlib/pyplot.py”,第 115 行,在 _backend_mod、new_figure_manager、draw_if_interactive、_show = pylab_setup()
pylab_setup 中的文件“/home/manuelanayantarajeyaraj/usr/myProject/my_project/lib/python3.5/site-packages/matplotlib/backends/init.py”,第 62 行 [后端名称],0)
文件“/home/manuelanayantarajeyaraj/usr/myProject/my_project/lib/python3.5/site-packages/matplotlib/backends/backend_tkagg.py”,第 4 行,在 从 。 import tkagg # 将图像绘制到 Tk photo blitter 扩展。
文件“/home/manuelanayantarajeyaraj/usr/myProject/my_project/lib/python3.5/site-packages/matplotlib/backends/tkagg.py”,第 5 行,在 从六.moves 导入 tkinter 作为 Tk
get 中的文件“/home/manuelanayantarajeyaraj/usr/myProject/my_project/lib/python3.5/site-packages/six.py”,第 92 行 结果 = self._resolve()
_resolve 中的文件“/home/manuelanayantarajeyaraj/usr/myProject/my_project/lib/python3.5/site-packages/six.py”,第 115 行 返回 _import_module(self.mod)
_import_module 中的文件“/home/manuelanayantarajeyaraj/usr/myProject/my_project/lib/python3.5/site-packages/six.py”,第 82 行 进口(名称)
文件“/usr/lib/python3.5/tkinter/init.py”,第 38 行,在 raise ImportError(str(msg) + ',请安装python3-tk包')
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。
在这方面的任何建议都将受到高度赞赏。
【问题讨论】:
-
请显示
dpkg -s python3-tk的输出。可能你已经为 python3.6 安装了 python3-tk。但你需要python3.5
标签: python-3.x matplotlib tkinter ubuntu-16.04 importerror