首页 > 解决方案 > python3.6 无法导入 tkinter & 在哪里为 python3.6 安装 tkinker

问题描述

我正在尝试使用 python3.6 导入 matplotlib.pyplot,但出现错误。

ModuleNotFoundError:没有名为“_tkinter”的模块

直接在 python 脚本中导入 tkinter 会产生相同的错误。

我也试过安装tkinter,但是在python3.6中还是导入失败

$ 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.5.1-1).
The following packages were automatically installed and are no longer required:
  libexpat1:i386 libmpdec2:i386 libpython3-dev libpython3-stdlib:i386 libpython3.5-dev libpython3.5-minimal:i386
  libpython3.5-stdlib:i386 libreadline6:i386 libsnapd-glib1 libsqlite3-0:i386 libssl1.0.0:i386 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-headers-4.13.0-38
  linux-headers-4.13.0-38-generic linux-image-4.13.0-36-generic linux-image-4.13.0-37-generic linux-image-4.13.0-38-generic
  linux-image-extra-4.13.0-36-generic linux-image-extra-4.13.0-37-generic linux-image-extra-4.13.0-38-generic
  linux-signed-image-4.13.0-37-generic linux-signed-image-4.13.0-38-generic snapd-login-service
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

$ python
Python 3.6.3 (default, Apr 13 2018, 13:00:29) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/tkinter/__init__.py", line 36, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'

安装 python3.6-tk 给出

 $ sudo apt-get install python3.6-tk
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package python3.6-tk
E: Couldn't find any package by glob 'python3.6-tk'
E: Couldn't find any package by regex 'python3.6-tk'

Matplotlib 和 tkinter 在使用 python2.7 和 3.5 时工作正常。我想问题是为python3.6安装tkinker,但我没有安装它。

谢谢

标签: matplotlibtkinterpython-3.6

解决方案


推荐阅读