Python3下提示No module named tkinter问题处理

在Python3下运行Matplotlib之时,提示No module named 'tkinter'这个问题,下面记录下解决过程,并尝试分析过程中的解决思路利弊得失,以资后效,这里重点提示需要关注错误信息的分析,这个是第一现场。
 
环境介绍
 
ASP站长网任何技术问题的出现以及修复都是依赖于系统环境以及特定版本的,这里首先描述如下:
 
Ubuntu: 18.04
 
tkinter的问题描述
 
原程序中基于matplotlib来进行绘图操作,其中在运行过程中,报出来了错误信息。由于原程序大部分无关问题本身,且日志本身比较多,这里仅仅截取关键信息:
 
import tkinter as Tk
ModuleNotFoundError: No module named 'tkinter'
 
Python3下提示"No module named _tkinter"问题解决
 
问题初步分析
 
用过python的朋友都知道,碰到类似的问题,比如import Error,大概率情况下都是某个包未安装,故第一反应就是某个包缺失了,于是首先进行了包和类库的查询:
 
linuxidc@linuxidc:~$ pip3 search tkinter
 
结果发现大量的包,被匹配到,其中若干相关的包有tkinter,这些信息基本上没有帮助。
 
..................
tkinter.help (2.0) - Small Preview of Tkinter Widgets
tkinter3000 (1.1-20051211) - Widget Construction Kit for Tkinter
tkinterhtml (0.7) - Python wrapper for Tkhtml3 (http://tkhtml.tcl.tk/)
tkinterquickhelper (1.5.18) - Helpers for tkinter, extra windows.
tkintertable (1.2) - Extendable table class for Tkinter
.......................
 
于是尝试直接安装tkinter,结果没有发现tkinter包
 
linuxidc@linuxidc:~$ pip3 install tkinter
Collecting tkinter
Exception:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/lib/python3/dist-packages/pip/commands/install.py", line 353, in run
    wb.build(autobuilding=True)
  File "/usr/lib/python3/dist-packages/pip/wheel.py", line 749, in build
    self.requirement_set.prepare_files(self.finder)
  File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 554, in _prepare_file
    require_hashes
  File "/usr/lib/python3/dist-packages/pip/req/req_install.py", line 278, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "/usr/lib/python3/dist-packages/pip/index.py", line 465, in find_requirement
    all_candidates = self.find_all_candidates(req.name)
  File "/usr/lib/python3/dist-packages/pip/index.py", line 423, in find_all_candidates
    for page in self._get_pages(url_locations, project_name):
  File "/usr/lib/python3/dist-packages/pip/index.py", line 568, in _get_pages
    page = self._get_page(location)
  File "/usr/lib/python3/dist-packages/pip/index.py", line 683, in _get_page
    return HTMLPage.get_page(link, session=self.session)
  File "/usr/lib/python3/dist-packages/pip/index.py", line 795, in get_page
    resp.raise_for_status()
  File "/usr/share/python-wheels/requests-2.18.4-py2.py3-none-any.whl/requests/models.py", line 935, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://pypi.org/simple/tkinter/
 
什么是tkinter, tcl ,tk
 
tkinter其实是Python调用tcl程序的标准Python程序,可以通过这个interface调用tcl的程序,因为在大多数的unix系统中都内置了很多的tcl程序和命令。
 
Tcl 是“工具控制语言(Tool Command Language)”的缩写,其面向对象为otcl语言。Tk 是 Tcl“图形工具箱”的扩展,它提供各种标准的 GUI 接口项,以利于迅速进行高级应用程序开发。

dawei

【声明】:九江站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。