9

I am trying to invoke the tool on Centos server from the Ubantu terminal.I am getting the following error.

Tk initialization failed: no display name and no $DISPLAY environment variable.

Please Help me with this.Thanks in advance.

  • I upgraded `matplotlib-2.2.3` to `matplotlib-3.0.2`, having solved this problem. For a simple test: `import matplotlib;matplotlib.use('TkAgg');import matplotlib.pyplot as plt;plt.plot(range(10))` – MeadowMuffins May 13 '20 at 06:29

3 Answers3

8

Connect to your CentOS machine with ssh -Y which (per man ssh)

Enables trusted X11 forwarding. Trusted X11 forwardings are not subjected to the X11 SECURITY extension controls.

That will allow your Tk process to connect to X11 on your Ubuntu machine.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
6

I work on Ubuntu. I had the same problem while using gitk on remote machines. So I tried following

ssh <username>@ip and ran gitk& got the "no display name and no $DISPLAY environment variable." error

ssh -X <username>@ip and ran gitk& it worked!
ssh -Y <username>@ip and ran gitk& it worked!

Thanks for the solution by Elliott Frisch.

Neuron
  • 5,141
  • 5
  • 38
  • 59
Aakash Naik
  • 61
  • 1
  • 1
1

I was having same issue using gitk on a new local machine with Ubuntu 21.04 and this solved my problem

export DISPLAY=:0
  • To start a script with the DISPLAY variable you can also use: ```env -i DISPLAY=:0 command_or_script``` – koyaanisqatsi Jul 15 '21 at 08:50
  • and for permanent solution, can use this link https://stackoverflow.com/questions/13046624/how-to-permanently-export-a-variable-in-linux – Suleman Uzair Jul 18 '21 at 20:26