当我在 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/