Python 为什么我在第6行得到最近一次调用的回溯和文件字符串

Python 为什么我在第6行得到最近一次调用的回溯和文件字符串,python,random,Python,Random,下面是我的python代码。当我每次在编译器中运行这段代码时,我都会遇到下面这样的错误 错误: Traceback (most recent call last): File "main.py", line 4, in <module> turtle.setup(850, 850) File "<string>", line 6, in setup File "/usr/lib64/python2.7/lib-tk/turtle.py", line 3

下面是我的python代码。当我每次在编译器中运行这段代码时,我都会遇到下面这样的错误

错误:

Traceback (most recent call last):
  File "main.py", line 4, in <module>
    turtle.setup(850, 850)
  File "<string>", line 6, in setup
  File "/usr/lib64/python2.7/lib-tk/turtle.py", line 3553, in Screen
    Turtle._screen = _Screen()
  File "/usr/lib64/python2.7/lib-tk/turtle.py", line 3569, in __init__
    _Screen._root = self._root = _Root()
  File "/usr/lib64/python2.7/lib-tk/turtle.py", line 458, in __init__
    TK.Tk.__init__(self)
  File "/usr/lib64/python2.7/lib-tk/Tkinter.py", line 1820, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable
回溯(最近一次呼叫最后一次):
文件“main.py”,第4行,在
海龟。设置(850850)
设置中第6行的文件“”
文件“/usr/lib64/python2.7/lib tk/turtle.py”,第3553行,在屏幕中
海龟。_screen=_screen()
文件“/usr/lib64/python2.7/lib-tk/turtle.py”,第3569行,在__
_屏幕。_root=self。_root=_root()
文件“/usr/lib64/python2.7/lib-tk/turtle.py”,第458行,在__
TK.TK.\uuuuu初始化(self)
文件“/usr/lib64/python2.7/lib-tk/Tkinter.py”,第1820行,在__
self.tk=\u tkinter.create(屏幕名、基本名、类名、交互、wantobjects、useTk、同步、使用)
_tkinter.TclError:没有显示名称和$display环境变量
我的代码:

import random
import turtle

turtle.setup(850, 850)
turtle.penup()
turtle.speed('fastest')
turtle.tracer(0, 0)

x = 0
y = 0

for i in range(1, 16000):
    r = random.uniform(0, 1)

    if r < 0.1:
        nextX = 0
        nextY = float(0.16 * y)

        x = nextX
        y = nextY

    elif r < 0.88:
        nextX = float(0.85 * x * 0.04 * y)
        nextY = float(-0.04 * x * 0.85 * y + 1.6)

        x = nextX
        y = nextY

    elif r < 0.93:
        nextX = float(0.20 * x * -0.26 * y)
        nextY = float(0.23 * x * 0.22 * y + 1.6)

        x = nextX
        y = nextY

    else:
        nextX = float(-0.15 * x * 0.28 * y)
        nextY = float(0.26 * x * 0.24 * y + 0.44)

        x = nextX
        y = nextY    


    turtle.goto(x*40, y*40)
    turtle.dot(2, 'green')

turtle.done()
随机导入
进口海龟
海龟。设置(850850)
乌龟
乌龟。速度(“最快”)
海龟追踪器(0,0)
x=0
y=0
对于范围(11600)内的i:
r=随机均匀(0,1)
如果r<0.1:
nextX=0
nextY=浮动(0.16*y)
x=nextX
y=nextY
elif r<0.88:
nextX=浮动(0.85*x*0.04*y)
nextY=浮动(-0.04*x*0.85*y+1.6)
x=nextX
y=nextY
elif r<0.93:
nextX=浮动(0.20*x*-0.26*y)
nextY=浮动(0.23*x*0.22*y+1.6)
x=nextX
y=nextY
其他:
nextX=浮动(-0.15*x*0.28*y)
nextY=浮动(0.26*x*0.24*y+0.44)
x=nextX
y=nextY
乌龟。后藤(x*40,y*40)
海龟。圆点(2,‘绿色’)
乌龟
这是我第一次发现的未定义错误之一。
我怎样才能解决这个问题?此代码中有什么错误。非常感谢您提前解决了这一问题,如果您在远程主机上通过ssh启动脚本(例如),通常会发生这种情况,因为没有显示,并且无法设置显示环境变量。在哪里运行脚本?

没有显示环境变量集。你的设置是什么?你是在本地Linux PC上运行这个吗?在在线终端上,我认为这是一个原因