turtle库无法直接用终端的指令用pip安装(至少我的电脑是这样)。网上只有windows的解决方案,确找不到mac的解决方案,虽然道理相似,但是还是花了一整个上午的时间才安装成功。
解决步骤:
1.按照给定的链接(https://files.pythonhosted.org/packages/ff/f0/21a42e9e424d24bdd0e509d5ed3c7dfb8f47d962d9c044dba903b0b4a26f/turtle-0.0.2.tar.gz),把turtle包下载到本地,手动解压,在这个文件夹中找到setup.py,第40行修改为
except (ValueError, ve):
2.很重要
在终端中输入指令:
Python3 -m pip install -e /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/turtle-0.0.2
**说明:**一般来说,默认的python是系统自带的,而我们要对python3进行操作;-e后面是turtle的路径,根据自己安装的情况加以修改。PS:这串指令网上几乎没有而且给的很简略。但是却很重要!!!
3.打开编译器测试turtle能否正常使用
如果:
仍然显示找不到,则 按住command,鼠标点击turtle,进入源代码:
进行如上图所示的修改(142,143行注释加入一个列表),列表内容为:
__all__ = ['ScrolledCanvas', 'TurtleScreen', 'Screen', 'RawTurtle', 'Turtle', 'RawPen', 'Pen', 'Shape', 'Vec2D', 'back',
'backward', 'begin_fill', 'begin_poly', 'bk', 'addshape', 'bgcolor', 'bgpic', 'bye', 'clearscreen',
'colormode', 'delay', 'exitonclick', 'getcanvas', 'getshapes', 'listen', 'mainloop', 'mode', 'numinput',
'onkey', 'onkeypress', 'onkeyrelease', 'onscreenclick', 'ontimer', 'register_shape', 'resetscreen',
'screensize', 'setup', 'Terminator', 'setworldcoordinates', 'textinput', 'title', 'tracer', 'turtles',
'update', 'window_height', 'window_width', 'write_docstringdict', 'done', 'circle', 'clear', 'clearstamp',
'clearstamps', 'clone', 'color', 'degrees', 'distance', 'dot', 'down', 'end_fill', 'end_poly', 'fd',
'fillcolor', 'filling', 'forward', 'get_poly', 'getpen', 'getscreen', 'get_shapepoly', 'getturtle', 'goto',
'heading', 'hideturtle', 'home', 'ht', 'isdown', 'isvisible', 'left', 'lt', 'onclick', 'ondrag', 'onrelease',
'pd', 'pen', 'pencolor', 'pendown', 'pensize', 'penup', 'pos', 'position', 'pu', 'radians', 'right', 'reset',
'resizemode', 'rt', 'seth', 'setheading', 'setpos', 'setposition', 'settiltangle', 'setundobuffer', 'setx',
'sety', 'shape', 'shapesize', 'shapetransform', 'shearfactor', 'showturtle', 'speed', 'st', 'stamp', 'tilt',
'tiltangle', 'towards', 'turtlesize', 'undo', 'undobufferentries', 'up', 'width', 'write', 'xcor', 'ycor']
大功告成!!!
import turtle
radius=eval(input())
col=["red","blue","green","yellow","black"]
coordA=(-2.2*radius,0,2.2*radius,-1.1*radius,1.1*radius)#各圆绘制起点坐标x值, radius为半径
coordB=(0,0,0,-1.1*radius,-1.1*radius) #各圆绘制起点坐标y值, radius为半径
turtle.penup()
for i in range(0,5):
turtle.goto(coordA[i],coordB[i])
#turtle.speed(100)
turtle.color(col[i])
turtle.pensize(5)
turtle.pendown()
turtle.circle(radius)
turtle.penup()
希望对热衷于python的mac用户带来帮助!
如有问题,请在评论区中提出。