Reputation: 12452
Linked Question: Mac OS X: _tkinter.TclError: no display name and no $DISPLAY environment variable
The above has the same issue but the answer to that doesn't apply to me.
a.py
from Tkinter import *
root = Tk()
canvas = Canvas(bg='white', width = 200, height = 200)
canvas.pack()
canvas.create_line(0, 0, 199, 199, fill="blue", width = 5)
canvas.create_line(0, 199, 199, 0, fill="blue", width = 5)
canvas.update()
canvas.postscript(file = "x.ps")
root.mainloop()
a.py is on a remote server
This works fine when I connect to a server via VNC and run it.
But when I connect to a server via Putty on windows and run it, it gives me "no display name and no diplay environment variable"
1) Is it possible to run this through Putty?
2) Can python know if a connection is made through putty and maybe raise my own error instead of TclError?
Upvotes: 2
Views: 7851
Reputation: 33203
You need to run an X server on your windows machine and then enable X11 forwarding in your putty session before you log in (see the Connection / SSH / X11 property page in PuTTY). In the past I've used Xming which is free and eXceed which was not. Once you have an X server on the machine you actually are looking at and forward the X connection over the ssh link, it will setup the DISPLAY environment variable on the remote machine so that X clients can communicate back to the display server. Otherwise, without a DISPLAY setup Tk will raise an error - as you are seeing.
Upvotes: 3