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

3

16

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'
Ashla answered 28/7, 2021 at 5:21 Comment(5)
_tkinter, so your python might not be configured for tkinterShanitashank
how do I configure it?Ashla
brew install python-tk tryShanitashank
It worked, but can you tell me what is pip3 install tk then?Ashla
@Ashla tk is tensorkit on pypi, not tkinter. pypi.org/project/tkEddi
N
50

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.

Nitza answered 28/7, 2021 at 5:43 Comment(4)
It worked for me. a point to note is: I'm using python 3.10 so I have to specify version when install tk like brew install [email protected] otherwise it won't work.Tenatenable
Thanks, Richard! It worked for me with the version.Centric
Thanks @Richard, after trying zillions of other posted solutions, this did the trickMisshape
On Mac OS make sure you have Command Line Tools installed from Xcode first. xcode-select --install.Wieland
D
1

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
Depict answered 15/6, 2022 at 21:13 Comment(0)
J
0

If you are in macOS, you can run the below commands to install python-tk. I have tested it on the latest macOS Ventura 13.1 and it worked like a charm.

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

Jahdiel answered 17/1, 2023 at 19:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.