I'm getting _tkinter.TclError: couldn't connect to display "localhost:10.0"
when SSH'ing (with -X
) into my Ubuntu 16.04 servers, running this script
from os import path
from wordcloud import WordCloud
import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.use('Agg')
d = path.dirname(__file__)
text = open(path.join(d, 'words.txt')).read()
wordcloud = WordCloud().generate(text)
# Configure plot
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
# lower max_font_size
wordcloud = WordCloud(max_font_size=40).generate(text)
plt.figure()
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.savefig("comments.png")
This script is using Wordcloud (https://github.com/amueller/word_cloud/). words.txt
is a bunch of words that I intend to turn into a wordcloud. What's supposed to happen is the cloud gets saved as comments.png (but not displayed) on the server I'm ssh'ing into.
I had the same problem working with Tensorflow using Ubuntu 16.04 via SSH.
Try using Agg rendering engine instead of X11 (it worked for me).
Adding the following lines did the trick
import matplotlib
matplotlib.use('Agg')
Thanks to @Mark from this thread: Problem running python/matplotlib in background after ending ssh session
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With