Can';t在Python2.x和Python3.x中导入turtle模块
我想在Python中使用模块。但当我导入turtle模块时,我有以下错误:Can';t在Python2.x和Python3.x中导入turtle模块,python,user-interface,turtle-graphics,Python,User Interface,Turtle Graphics,我想在Python中使用模块。但当我导入turtle模块时,我有以下错误: $ python Python 2.7.3 (default, Sep 26 2012, 21:51:14) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import turtle Traceback (most recent call last):
$ python
Python 2.7.3 (default, Sep 26 2012, 21:51:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import turtle
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "turtle.py", line 3, in <module>
myTurtle = turtle.Turtle()
AttributeError: 'module' object has no attribute 'Turtle'
$python
Python 2.7.3(默认值,2012年9月26日,21:51:14)
[GCC 4.7.2]关于linux2
有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。
>>>进口海龟
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“turtle.py”,第3行,在
myTurtle=海龟。海龟()
AttributeError:“模块”对象没有属性“海龟”
对于Python 3.x:
$ python3
Python 3.2.3 (default, Sep 30 2012, 16:41:36)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import turtle
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "turtle.py", line 3, in <module>
myTurtle = turtle.Turtle()
AttributeError: 'module' object has no attribute 'Turtle'
$python3
Python 3.2.3(默认值,2012年9月30日,16:41:36)
[GCC 4.7.2]关于linux2
有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。
>>>进口海龟
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“turtle.py”,第3行,在
myTurtle=海龟。海龟()
AttributeError:“模块”对象没有属性“海龟”
我在Kubuntu Linux 12.10下工作。我和特金特·圭玩过。没问题。海龟模块会发生什么情况?您调用了一个脚本
turtle.py
,它在标准库中对turtle
模块进行阴影处理。重命名它。请尝试
来自tutle imort Turtle:要导入模块,它将对您起作用您可以通过安装
python tk
包来解决此问题
sudo apt-get install python3-tk
我也遇到了同样的问题,但我找到了答案:“重命名它!”它成功了。无论如何,不要使用“进口海龟”。使用“from turtle import*”。我无法找到任何带有
turtle.py
的文件,因此我卸载了Python并从Python.org重新安装了64位版本。这一次,在我将以下两行代码输入终端(黑屏)后,程序运行
当然,在安装之前,您的海龟可以被称为其他名称,而不一定是shelly,请尝试使用:
from turtle import *
g=Turtle()
begin_fill()
g.forward(100)
检查此操作是否有效(导入和星号之间有空格)同时确保运行: 哪条蟒蛇 然后用它设置文件的顶部
#!/usr/bin/python
import Tkinter
from turtle import *
或者,如果位置不正确,则需要使用.py重命名该文件
然后使用python filename.py执行您能详细解释一下吗?当前目录中有文件turtle.py。我尝试导入海龟模块。和python解释器搜索turtle模块,首先在我的当前文件夹中搜索turtle.py,而不是在python库目录中搜索turtle.py。请重新检查您的输入错误
#!/usr/bin/python
import Tkinter
from turtle import *