Question

IMPORTANT i did not notice that there were two different places where i had to change the settings from Qt4 to SVG. I changed them both and the problem regarding the "no Turtle found" was solved. I need to thank Jonathan March, who turned me in the right direction with the link he suggested.

PROBLEM SOVED!!

I'm using Canopy 1.3.0.1715 (32bit) on a MacBook Pro 64bit OS 10.9.2.

When i try to use

from turtle import Turtle

Canopy says

name 'Turtle' is not defined

Here is my code, named draw.py (i want to draw a square):

from turtle import Turtle
t = Turtle()
def drawsquare(t, x, y, side):
    t.up()
    t.goto(x,y)
    t.setheading(270)
    t.down()
    for count in range(4):
        t.forward(side)
        t.left(90)

I also created a file turtle.cfg like this

width = 300
height = 200
using_IDLE = True
colormode = 255

Please be as simple as you can, i just recently started using Python. Thanks everyone.

Était-ce utile?

La solution

from turtle import Turtle

works for me on Canopy-32 bit on Mac64 (running in the Canopy python shell).

First thing to check: did you name some file turtle.py? If so, rename the file, delete the file turtle.pyc in the same directory if it exists, and try again. (If you name your file turtle.py, then python has no way to find the standard turtle module.)

Otherwise:

Where are you running this? In the Canopy python (ipython) shell? Or did you start up Python some other way?

Wherever it is, what do you see when you type this?:

import sys, turtle
print sys.prefix
print turtle.__file__

Also, while this should not account for your import failure, be sure to read and follow the following: https://support.enthought.com/entries/21793229-Using-Tkinter-Turtle-in-Canopy-s-IPython-panel

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top