【问题标题】:Is tkinter renamed in Python 3.9.0b3?tkinter 是否在 Python 3.9.0b3 中重命名?
【发布时间】: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,即:pip3pip3.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 没有被重命名。
  • 如果您安装了tcltk 开发包,当您从源代码构建Python 时,tkinter 将正确构建。见我的result
  • @acw1668 ,该怎么做?
  • 您是否从源代码构建 Python 3.9?如果是,那么正如我所说,您必须确保在构建 Python 3.9 之前安装了 tcl-devtk-dev 包。

标签: python-3.x tkinter error-handling python-import importerror


【解决方案1】:

好的,知道出了什么问题(感谢@acw1668)。我从源代码安装了 python 3.9,没有依赖项(tk-devtcl-dev

  • 所以我做的第一件事是 uninstalling Python3.9
  • 然后使用 this method(来自 deadsnakes ppa)重新安装它
  • 然后在终端中运行 sudo apt install python3.9-tk
  • 现在一切正常。

感谢@Noah-J-Standerson 推荐这个方法

【讨论】:

    猜你喜欢
    • 2010-10-14
    • 1970-01-01
    • 2019-11-29
    • 2022-12-02
    • 2012-08-30
    • 2014-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多