30

I'm trying to run a very simple code that outputs a .png file in a cluster. Here's the code:

import matplotlib.pyplot as plt
import numpy as np

x = np.random.randn(60)
y = np.random.randn(60)

plt.scatter(x, y, s=20)

out_png = 'path/to/store/out_file.png'
plt.savefig(out_png, dpi=150)

If I run this code with the command python simple_code.py in my system which has matplotlib 1.2.1 installed I get the warning:

Unable to load library icui18n "Cannot load library icui18n:

The .png image is still produced so I have no problems here. But if I use the same command and code in a cluster which has matplotlib 1.3.0 installed it fails with the error:

Traceback (most recent call last):
  File "simple_code.py", line 33, in <module>
    plt.scatter(x, y, s=20)
  File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 3078, in scatter
    ax = gca()
  File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 803, in gca
    ax =  gcf().gca(**kwargs)
  File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 450, in gcf
    return figure()
  File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 423, in figure
    **kwargs)
  File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 79, in new_figure_manager
    return new_figure_manager_given_figure(num, figure)
  File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 87, in new_figure_manager_given_figure
    window = Tk.Tk()
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1712, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable

What is happening here?


Add, this is the script I use to login into the cluster:

#!/usr/bin/expect

set login "user"
set addr "address1"
set addr2 "address2"
set pw "password"

spawn ssh -X $login@$addr
expect "$login@$addr\'s password:"
send "$pw\r"
expect "$login@host:"
send "ssh -X $addr2\r"
expect "$login@$addr\'s password:"
send "$pw\r"
interact
Gabriel
  • 40,504
  • 73
  • 230
  • 404
  • 2
    Are you running this through `ssh`? – SethMMorton Oct 11 '13 at 02:05
  • 1
    Yes I am SethMMorton. I set the job and let it run in the cluster through `ssh`. – Gabriel Oct 11 '13 at 02:06
  • 3
    When you call `ssh`, do you use the `-X` flag? – SethMMorton Oct 11 '13 at 02:09
  • Nope, I just call the `ssh` twice with no flag. This question I made yesterday explains how I login: http://unix.stackexchange.com/questions/94334/script-to-login-to-ssh-twice – Gabriel Oct 11 '13 at 02:10
  • 4
    I added the `ssh` tag to this post. I think you should change the title to "no display name and no $DISPLAY environment variable using tkinter through ssh" because that's the real problem and more easily searchable for others with the same problem (I don't like changing other people's titles.). – SethMMorton Oct 11 '13 at 02:13
  • Done Seth, thanks. Please see my comment in your answer. – Gabriel Oct 11 '13 at 02:15
  • The script you are using is not using the `-X` flag... – SethMMorton Oct 11 '13 at 02:24
  • That's because that is the *original* script. Let me change it to show how I setup the `-X` flags as you instructed. – Gabriel Oct 11 '13 at 02:25
  • You should call it like `ssh -X ...`, not `ssh ... -X`. That *might* be the issue. – SethMMorton Oct 11 '13 at 02:28
  • That's actually what I tried first and then changed to putting the flag last. That did not work either but I'll edit the question the same. – Gabriel Oct 11 '13 at 02:29
  • 3
    I am going to delete my answer and direct you to the following SO question. It's actually almost an exact duplicate of this question. http://stackoverflow.com/q/2801882/1399279. It will solve your problem. – SethMMorton Oct 11 '13 at 02:48
  • Thank you very much Seth, that has apparently fixed the issue. Cheers. – Gabriel Oct 11 '13 at 11:06

1 Answers1

36

Your problem is in ssh command. What you need to do is to write it this way:

ssh -X "your_login"
tshepang
  • 12,111
  • 21
  • 91
  • 136
luturo
  • 393
  • 2
  • 3
  • 12
    As an FYI, this was not the solution to the OP's problem. I had suggested in my own answer and then deleted it when the OP told me that it did not fix the problem. The problem identical to the one given here, and it also contains the solution: http://stackoverflow.com/q/2801882/1399279. – SethMMorton Apr 17 '14 at 03:37
  • 2
    Just a reminder, `ssh -X` may at times give you warnings like `Warning: untrusted X11 forwarding setup failed: xauth key data not generated` in which case you should do `ssh -Y` instead. – Ethan Chen Apr 08 '17 at 00:30
  • The -Y worked for me (the -X didn't). Thanks @YuxuanChen – Serendipity Apr 16 '19 at 09:28