Attribute Error module 'turtle' has no attribute 'Turtle'

Viewed 46

This problem occurred to me quite recently. I have no idea what i am doing wrong due to me being a beginner in python. If anyone is interested I am using a Raspberry pi 400 and I am using VSC but anyways here is my code:

import turtle
import random

pat=turtle.Turtle()
colours=["orange","blue","red","yellow", "cyan"]
turtle.Screen().bgcolor("black")

for i in range(200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000):
    for i in range(2):
        pat.forward(300)
        pat.right(100)
        pat.right(100)
        pat.forward(300)
        pat.right(100)
        pat.left(5)
        pat.color(random.choice(colours))
1 Answers

Could it be that you have a file named turtle.py in the same folder, or in any other folder contained in the PYTHONPATH environment variable? In that case import turtle might not load the turtle package, but instead the local Python file, which does not contain an executable object named Turtle and hence the AttributeError is raised when calling turtle.Turtle().

Related