我正在尝试学习如何在 Python 中使用 tkinter 模块,但是当我在本地运行它时,出现以下错误:
Traceback (most recent call last):
File "emailer", line 1, in <module>
from tkinter import messagebox
ImportError: No module named tkinter
我尝试过 pip install tkinter
和 sudo pip install tkinter
,这会引发以下错误:
Could not find a version that satisfies the requirement tkinter (from versions: )
No matching distribution found for tkinter
最后,在终端中运行 which python
时,输出为 /usr/bin/python
最佳答案
If you are using Python from a python.org 64-bit/32-bit Python installer for Mac OS X 10.6 and later, you should only use IDLE or tkinter with an updated third-party Tcl/Tk 8.5 (not 8.6), like ActiveTcl 8.5 installed.
If you are using Mac OS X 10.6, do not use IDLE or Tkinter from the Apple-supplied Python 2.6.1 in Mac OS X 10.6. If possible, install and use a newer version of Python and of Tcl/Tk.
If you are using Mac OS X 10.7 or later, the Apple-supplied Tcl/Tk 8.5 still has serious bugs that can cause application crashes. If you wish to use IDLE or Tkinter, install and use a newer version of Python and of Tcl/Tk.
实际上你可以使用自制
:
brew install tcl-tk
brew link tcl-tk --force
看看tcltk .
关于python - 如何在 macOS Sierra 上使用 tkinter 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42345189/