Error message received when trying to import turtle (python 3.9, m1 Mac)

Viewed 1779

When I try to import the python 3 graphical library, turtle, on my m1 MacBook, I get an error message:

 david@Davids-MacBook-Air Python Coding Files % /opt/homebrew/bin/python3 "/Users/david/Desktop/Python Coding Files/hello.py"
Traceback (most recent call last):
  File "/Users/david/Desktop/Python Coding Files/hello.py", line 1, in <module>
    import turtle
  File "/opt/homebrew/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/turtle.py", line 107, in <module>
    import tkinter as TK
  File "/opt/homebrew/Cellar/python@3.9/3.9.6/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'

I see it has the library tkinter written in it for some reason. This is weird because on my other Mac, an intel based Mac, with the same python 3 version, and no library such as tkinter install, I didnt get an error message when trying to import turtle

Does anybody know what the problem is?

1 Answers

Python 3's turtle module has always used tkinter. Your other Mac must have tkinter installed. It used to be shipped with Python, but now you need to install it. Assuming you use HomeBrew:

brew install python-tk
Related