python - 在 Ubuntu 18.04 中为 python 3.7.3 安装 tkinter

标签 python ubuntu tkinter

当我在 Ubuntu 18.04 上的 python 3.7.3 中导入 tinker 时:

>>> import tkinter

我有:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/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'

然后我使用以下两种方式安装 tk:
sudo apt-get install python3-tk

它没有用。

我也做了Tkinter module not found on Ubuntu中的所有事情,还是不行。
我注意到当我这样做时:
sudo apt-get install python3.7-tk

它说:
Note, selecting 'python3-tk' instead of 'python3.7-tk'
python3-tk is already the newest version (3.6.9-1~18.04).

tk 自动安装在 python 3.6.9 下吗?我怎样才能解决这个问题?

我还看到了 https://wiki.python.org/moin/TkInter 的解决方案:

If it fails with "No module named _tkinter", your Python configuration needs to be modified to include this module (which is an extension module implemented in C). Do not edit Modules/Setup (it is out of date). You may have to install Tcl and Tk (when using RPM, install the -devel RPMs as well) and/or edit the setup.py script to point to the right locations where Tcl/Tk is installed. If you install Tcl/Tk in the default locations, simply rerunning "make" should build the _tkinter extension.



有人可以解释如何执行本段中提到的步骤吗?

最佳答案

好的。我认为问题在于 Ubuntu 18.04 的最新版本 tkinter 是“python3-tk_3.6.9-1~18.04_i386.deb”。现在我发现python3.7.3的tk可用于其他系统(例如python3-tk_3.7.3-1_amd64.deb)。我可以在我的系统上下载和使用这些吗?

关于python - 在 Ubuntu 18.04 中为 python 3.7.3 安装 tkinter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59725147/

相关文章:

python - Tkinter 将鼠标点击绑定(bind)到框架

python - 如何将连续数据拆分成组?

python - 如何在 Python 3.4 中执行异步任务?

linux - 如何在 Ubuntu 上的文件中使用逻辑 AND 条件搜索关键字?

php - 无法在 Ubuntu 上连接到 MySQL 服务器

python - 将项目添加到 ttk.Treeview 时出现“不匹配的左括号”错误

python - 具有多个 View 参数的 Django 装饰器

python - Flask 是否具有与 Rails 初始化器等效的功能?

linux - 如何从控制台 linux 运行文件关联的应用程序

python - tkinter - 无限 Canvas "world"/"view"- 跟踪 View 中的项目