11

I want to play with turtle module in Python. But when i do import turtle module, i've the following error:

$ 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'

and for 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'

I working under Kubuntu Linux 12.10. I've played with Tkinter gui. There is no problem. What happen with turtle module?

Mind Mixer
  • 1,503
  • 3
  • 13
  • 15

7 Answers7

30

You've called a script turtle.py, which is shadowing the turtle module in the standard library. Rename it.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • can you explain this more? – Stephan Jul 08 '13 at 15:21
  • 2
    There is file turtle.py in current directory. I try to import turtle module. And python interpreter search turtle module and first seek turtle.py in my current folder instead of turtle.py from python library directory. – Mind Mixer Jul 08 '13 at 15:30
3

You can fix this problem by installing the python-tk package.

sudo apt-get install python3-tk
tmthydvnprt
  • 10,398
  • 8
  • 52
  • 72
0

I had the same problem but I found answer: "Rename it!" and it worked. anyways don't use 'import turtle'. Use 'from turtle import *'.

Ben
  • 1
0

I was unable to locate any file with turtle.py so I uninstalled Python and reinstalled a 64 bit version from Python.org. This time the program ran after I typed the following two lines of code into the terminal (black screen).

import turtle

shelly=turtle.Turtle()

Of course your turtle can be called other names and not necessarily shelly.

xskxzr
  • 12,442
  • 12
  • 37
  • 77
ICU
  • 1
0

before installing try using:

from turtle import *

g=Turtle()

begin_fill()

g.forward(100)

check out if this working or not(there is space between import and asterick sign)

Bartosz Konieczny
  • 1,985
  • 12
  • 27
0

Make sure also that you run:

which python Then set the top of your file with that.

#!/usr/bin/python
import Tkinter
from turtle import *

Or if you don't have the location correct, you need to rename the file with .py Then execute with python filename.py

Jonni2016aa
  • 144
  • 1
  • 3
-3

please try

from tutle imort Turtle: to import the module....it will work for you

tsegay
  • 1