Unable to import turtle module in Python 2.x and Python 3.x

I want to play with the turtle module in Python. But when I import the turtle module, I have 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 work under Kubuntu Linux 12.10. I played with Tkinter gui. No problems. What happens to the turtle module?

+8
source share
7 answers

You called the turtle.py script, which shades the turtle module in the standard library. Rename it.

+25
source

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

 sudo apt-get install python3-tk 
+2
source

I had the same problem, but I found the answer: "Rename it!". and it worked. in any case, do not use "import tortoise". Use "from import turtle."

0
source

I was unable to find any file using turtle.py , so I uninstalled Python and reinstalled the 64-bit version from Python.org. This time the program started after I entered the following two lines of code in the terminal (black screen).

 import turtle shelly=turtle.Turtle() 

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

0
source

before installation try using:

 from turtle import * g=Turtle() begin_fill() g.forward(100) 

check if it works or not (there is a space between import and asterisk)

0
source

Also make sure you run:

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

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

Or, if you have the wrong location, you need to rename the file using .py Then run with python filename.py

0
source

try

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

-2
source

Source: https://habr.com/ru/post/948954/


All Articles