ModuleNotFoundError: No module named ‘_tkinter’

有網友反應執行了我的程式在他的 Mac m1 電腦上,會顯示錯誤訊息:

<module>
    from tkinter import *
  File "/opt/homebrew/Cellar/[email protected]/3.9.7_1/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'

打開終端視窗(terminal)並執行以下命令來安裝 tkinter。
Open your terminal and run the following command to install tkinter.

# === UBUNTU / DEBIAN ===
sudo apt-get install python3-tk

# Make sure to specify correct Python version.
# For example, my Python 3.10, so I would install as
sudo apt-get install python3.10-tk

# === MacOS ===
brew install [email protected]

# if you run Python v3.9 run adjust command to
brew install [email protected]

# === Fedora ===
sudo dnf install python3-tkinter

# === CentOS ===
sudo yum install python3-tkinter

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *