Search code examples
pythonpython-3.xsshopensshssh-tunnel

tkinter.TclError: no display name and no $DISPLAY environment variable python


I want to execute my python file in a remote system using ssh. I exported the file to the remote system.

Here's the sample file:

import os
import time
import pymsgbox

pymsgbox.alert('Hi Afreeth ', 'Welcome')
if 'DISPLAY' not in os.environ: 
    pass

I want to execute it using ssh from my system and it should display in the remote system. But it fails

Error i got:

Traceback (most recent call last):
  File "cd1.py", line 5, in <module>
  File "pymsgbox/__init__.py", line 100, in alert
  File "pymsgbox/__init__.py", line 156, in _buttonbox
  File "tkinter/__init__.py", line 1871, in __init__
_tkinter.TclError: no display name and no $DISPLAY environment variable
[12113] Failed to execute script myprogram

How to fix it. I found some answers on stack but it doesn't solve me. If i go and execute it in the remote system, it works. But when i execute from my system,it fails. How to fix it.


Solution

  • Found the Answer: I just need to run export DISPLAY=:0 in their ssh session and programs run will run on the remote display. A quick example:

    paulsteven@smackcoders:~$ ssh afreeth@his_ipaddress
    afreeth@smackcoders:~$ export DISPLAY=:0
    afreeth@smackcoders:~$ firefox
    Firefox is now running on afreeth's display.