python - 尝试导入海龟时收到错误消息(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
有谁知道问题是什么?
解决方案
Python 3 的turtle
模块一直使用tkinter
. 您的另一台 Mac 必须已tkinter
安装。它曾经与 Python 一起提供,但现在您需要安装它。假设您使用 HomeBrew:
brew install python-tk
推荐阅读
- javascript - 如何修复 $scope 选择选项数组中未定义的结果?
- node.js - Firebase Cloud Functions 在 24 小时后直接删除节点
- excel - 无法从电子表格中剔除一些不需要的值
- python - 为什么回火 mcmc fit 不能很好地转换?
- cupy - 有没有办法在调用之前编译(即缓存)cupy RawKernel?
- javascript - 用javascript调用flask函数
- python - 如何在python中合并和组合具有相同id(索引)的行?
- laravel - 服务提供者未在 Laravel 5.8 中启动
- php - PHP/MySQL 错误:无法使用 PDO 执行 INSERT INTO
- python-3.x - 如何计算年度股票贝塔