python - Python模块乌龟没有正确导入
问题描述
这是我第一次在 python 中使用 turtle 模块,但我似乎无法导入它?这是我的代码:
import turtle
turtle.shape("turtle")
turtle.speed(1)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.exitonclick()
我运行这个$ python3 example.py
我得到
$ python3 example.py
Traceback (most recent call last):
File "example.py", line 1, in <module>
from turtle import *
File "/usr/lib/python3.7/turtle.py", line 107, in <module>
import tkinter as TK
ModuleNotFoundError: No module named 'tkinter'
如果我运行 Python2python example.py
$ python example.py
Traceback (most recent call last):
File "example.py", line 1, in <module>
import turtle
File "/usr/lib/python2.7/lib-tk/turtle.py", line 107, in <module>
import Tkinter as TK
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 42, in <module>
raise ImportError, str(msg) + ', please install the python-tk package'
ImportError: No module named _tkinter, please install the python-tk package
解决方案
它是
sudo apt install python3-tkinter
推荐阅读
- ios - 如何创建轮播视图
- java - 在执行实际操作之前对 Web 元素进行一些标准验证
- java - 不了解 Java 中的一些基本编译错误
- cassandra-3.0 - Cassandra 数据类型持续时间在 sstableloader 中失败
- reactjs - 我试图通过单击按钮返回上一页做出反应
- ios - AppleTV 上的 UICollectionView 中的 UICollectionView reloadData
- python - 如何将随机数作为索引提供给熊猫数据框?
- angular - 停止执行,直到订阅的观察者发出值
- javascript - 调用 window.alert 后按钮仍可点击
- javascript - LaTeX 公式嵌套