简体   繁体   中英

python turtle on mac not working

I am trying to use a python import of turtle but i get an error:

Traceback (most recent call last):
  File "turtle.py", line 1, in <module>
    import turtle
  File "/turtle.py", line 32, in <module>
    turtle.pensize(2)
AttributeError: 'module' object has no attribute 'pensize'

Does the python come with turtle or i have to download it separately?

My python is 2.7.2

You called your file turtle.py , so import turtle imports your program, not the module you want.

Rename your program and delete any turtle.py[co] files.

using turtle.py is causing the problem here. scrap that and use this instead

import turtle
turtlename = turtle.Turtle()
wn = turtle.Screen()

once you have done this use basic turtle comands like

turtlename.forward(90)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM