Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ModuleNotFoundError: No module named '_tkinter' on macOS [duplicate]

Tkinter doesn't work, it throws an error.

Installation:

% pip3 install tk

My code:

#!/usr/bin/env python3

import tkinter as tk

The error:

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/[email protected]/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'

2 Answers

For Python3 tkinter can be simply installed by,

brew install python-tk

pip sometimes wont work successfully on my Mac, especially with the High Sierra OS version. Brew can be used to install all kinds of software packages in mac.

like image 71
Coder94 Avatar answered Nov 20 '25 19:11

Coder94


I was having the same issue with the module name change in Python2 to Python3.. as stated in the previous post, "brew install python-tk" worked for me. I'm running the following:

  • Python 3.9.13 64-bit
  • vsCode 1.68.0
  • macOS Monterey
like image 21
Winston Avatar answered Nov 20 '25 21:11

Winston



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!