[英]ModuleNotFoundError: No module named '_tkinter' on macOS
Tkinter 不起作用,它會拋出錯誤。
% pip3 install tk
#!/usr/bin/env python3
import tkinter as tk
Traceback (most recent call last):
File "/Users/arghadip/Library/Application Support/CodeRunner/Unsaved/Untitled.py", line 4, in <module>
import tkinter as tk
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'
對於 Python3 tkinter 可以簡單地安裝,
brew install python-tk
pip 有時無法在我的 Mac 上成功運行,尤其是使用 High Sierra OS 版本。 mac可以使用brew安裝各種軟件包。
我在將 Python2 中的模塊名稱更改為 Python3 時遇到了同樣的問題。如上一篇文章中所述,“brew install python-tk”對我有用。 我正在運行以下內容:
如果您在 macOS 中,則可以運行以下命令來安裝python-tk
。 我已經在最新的 macOS Ventura 13.1 上對其進行了測試,效果非常好。
sudo chown -R $(whoami) /usr/local/share /usr/local/share/man /usr/local/share/man/man8
chmod u+w /usr/local/share /usr/local/share/man /usr/local/share/man/man8
brew install python-tk
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.