首页 > 解决方案 > 尝试导入海龟时收到错误消息(python 3.9,m1 Mac)

问题描述

当我尝试在我的 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'

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

有谁知道问题是什么?

标签: pythontkinterapple-m1python-3.9python-turtle

解决方案


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

brew install python-tk

推荐阅读