Don't understand this AttributeError: module 'turtle' has no attribute 'Turtle'

15,981

Solution 1

Change your file name with something else like turtle_something.py. Because of its conflicting with the turtle library.

Solution 2

The problem is resolved. I made a mistake of creating a python script, naming it "turtle.py" and saving it in the same folder where i had kept this code. So, it was interfering with the turtle library

Share:
15,981

Related videos on Youtube

Manish Kumar
Author by

Manish Kumar

Updated on June 04, 2022

Comments

  • Manish Kumar
    Manish Kumar almost 2 years
    #archimedes spiral by rays
    
    import math
    import turtle
    
    def spiral(t, a, b):
        diff=5
        number=500
        for i in range(number):
            t.penup()
            t.fd(a+b*i*diff*math.pi/180)
            t.pendown()
            t.lt(90)
            t.fd(10)
            t.bk(10)
            t.rt(90)
            t.penup()
            t.bk(a+b*i*diff*math.pi/180)
            t.lt(diff)
    
    
    bob=turtle.Turtle()
    bob.speed(1000)
    
    spiral(bob,0, 2)
    

    The code gives an error message as follows:

    RESTART: C:\Users\Manish Kumar\Desktop\TBN\repository\Competitive Programming\PYTHON\python scripts\archimedian_spiral.py
    
    Traceback (most recent call last):
      File "C:\Users\Manish Kumar\Desktop\TBN\repository\Competitive Programming\PYTHON\python scripts\archimedian_spiral.py", line 4, in <module>
        import turtle
    
    File "C:\Users\Manish Kumar\Desktop\TBN\repository\Competitive Programming\PYTHON\python scripts\turtle.py", line 7, in <module>
        bob=turtle.Turtle()
    
    AttributeError: module 'turtle' has no attribute 'Turtle'
    >>>
    

    I do not understand the error message. How can I make the code work? This code used to run smoothly some 3 to 4 months back.

    • Manish Kumar
      Manish Kumar over 5 years
      The problem os resolved. I had created a python code and named it "turtle.py" by mistake. It was saved in the same folder as the above code. So, it was interfering with the turtle library
  • Aiyion.Prime
    Aiyion.Prime about 4 years
    This answer should have been the accepted one, imho.