【发布时间】:2021-01-20 04:01:28
【问题描述】:
我刚刚升级到 python 3.9(之前我有 python 3.8.2)
我正在做一个必须使用 tkinter 模块的项目。
在 Python3.8.2 中一切正常
但是升级到 Python3.9 后,我得到了这个错误:
错误是:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.9/tkinter/__init__.py", line 37, in
<module>
import _tkinter # If this fails your Python may not be configured for
Tk
ModuleNotFoundError: No module named '_tkinter'
那么有人知道如何解决这个问题吗?
附注:
我尝试过使用
sudo apt install python3-tk
它只给出这个消息:
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-tk is already the newest version (3.8.2-1ubuntu1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
编辑:
我发现我的系统上安装了 2 个pip,即:pip3 和 pip3.9(我不知道如何)
一个熟悉的预先存在的pip3
当我做pip3 list
Package Version
------------------------ --------------------
aiohttp 3.6.2
apturl 0.5.2
astroid 2.4.2
async-timeout 3.0.1
attrs 20.2.0
autopep8 1.5.4
#(And many more...)
但是当我做 pip3.9 list 时,我只安装了 2 个模块:
Package Version
---------- -------
pip 20.2.3
setuptools 41.2.0
【问题讨论】:
-
我想你也需要升级系统包
python3-tk。 -
不,tkinter 没有被重命名。
-
如果您安装了
tcl和tk开发包,当您从源代码构建Python 时,tkinter将正确构建。见我的result。 -
@acw1668 ,该怎么做?
-
您是否从源代码构建 Python 3.9?如果是,那么正如我所说,您必须确保在构建 Python 3.9 之前安装了
tcl-dev和tk-dev包。
标签: python-3.x tkinter error-handling python-import importerror