以下以
macos
系统为例。
1. 安装Homebrew
参考:https://blog.csdn.net/Amio_/article/details/109694893
2. 安装Python
# 以下以安装`python 3.9版本`为例
brew install python@3.9
3. 使用tkinter
库
import tkinter
库时提示:
>>> import tkinter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.8/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'
>>>
提示很明显了,我当前macos big sur
系统未配置tk
,此时仅需安装**与python
版本匹配的tk
**即可。
brew install python-tk@3.9
再次尝试,解决问题。