尝试导入海龟时收到错误消息(python 3.9,m1 Mac)

4 python tkinter python-3.9 python-turtle apple-m1

当我尝试在 m1 MacBook 上导入python 3图形库turtle时,收到一条错误消息:

 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'
Run Code Online (Sandbox Code Playgroud)

tkinter我看到它出于某种原因写入了库。这很奇怪,因为在我的另一台 Mac(基于 Intel 的 Mac)上,具有相同的python 3版本,并且没有安装等库tkinter,在尝试导入时没有收到错误消息turtle

有人知道问题是什么吗?

Tim*_*rts 6

Python 3 的turtle模块一直使用tkinter. 您的另一台 Mac 必须已tkinter安装。它以前是随 Python 一起提供的,但现在您需要安装它。假设您使用 HomeBrew:

brew install python-tk
Run Code Online (Sandbox Code Playgroud)