简体   繁体   English

Python 模块海龟没有正确导入

[英]Python module turtle not importing correctly

This is my first time using the turtle module in python but I can't seem to import it?这是我第一次在 python 中使用海龟模块,但我似乎无法导入它? Here's my code:这是我的代码:

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()

I run this as $ python3 example.py And I get我将其作为$ 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'

If I run Python2 python example.py如果我运行 Python2 python 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

It was它是

sudo apt install python3-tkinter

This is a simple one to solve:这是一个简单的解决方案:

sudo apt-get install python3-tk

One of the other commenters suggested python-tk which wouldn't work for you here.其他评论者之一建议 python-tk 在这里对你不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM