MacOS Big Sur使用python3.95 tkinter报错:
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/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'
解决:
#安装对应的tkinter版本
brew install python-tk@3.9
Updating Homebrew...
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/python-tk%403.9-3.9.4.big_sur.bottle.tar.gz
######################################################################## 100.0%
==> Pouring python-tk@3.9-3.9.4.big_sur.bottle.tar.gz
🍺 /usr/local/Cellar/python-tk@3.9/3.9.4: 5 files, 133.1KB
#查看安装的版本
python3 -c 'import tkinter;print(tkinter.TkVersion);'
8.6
更新python3版本:
brew upgrade python@3.9