Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TclError: no display name and no $DISPLAY environment variable on EC2

I'd like to use iPython on an Amazon EC2 (Linux AMI). I've installed Anaconda and started iPython to test out some scripts I've already created. Right now I am only interested in running it in Terminal (not as Notebook).

At the beginning of my code I always do:

import json
import numpy as np
import pandas as pd
from pandas import Series, DataFrame

However, I tried CTRL + C from my text editor and then using %paste in Terminal I get the error:

TclError: no display name and no $DISPLAY environment variable

If I try to ssh -X name@host as per this suggestion No display name and no $DISPLAY environment variable using tkinter through ssh, I get:

/opt/X11/bin/xauth:  file /Users/adrianp/.Xauthority does not exist
Warning: untrusted X11 forwarding setup failed: xauth key data not generated
X11 forwarding request failed on channel 0

To fix that issue I tried https://superuser.com/questions/249045/x11-forwarding-from-amazon-ec2-ami but still got a warning:

 Warning: untrusted X11 forwarding setup failed: xauth key data not generated

And the same error:

TclError: no display name and no $DISPLAY environment variable

Per this suggestion Generating a PNG with matplotlib when DISPLAY is undefined (which seems irrelevant but I've tried everything) I did:

import matplotlib
matplotlib.use('Agg')

before importing anything else and still get the same error.

Any ideas on how to solve this problem? I'd really like to use the paste magic function to input functions/etc.

like image 601
measureallthethings Avatar asked Mar 06 '15 18:03

measureallthethings


People also ask

What is TclError in Python?

TclError): # happens when numeric fields are empty. return '' Example #4. Source Project: Python-GUI-Programming-with-Tkinter Author: PacktPublishing File: widgets.py License: MIT License. 6 votes.


1 Answers

This is more of a linux/X11 issue than a python question. Also, this process will probably be overkill - you'd be better just running ipython locally or launching a web notebook.

Anyway, you should:

  • install tigervnc
  • run vncserver (since this is an internet-facing server, use a secure passphrase or block the port in the firewall)
  • install tk (I think you have already done this)
  • edit sshd_config (most likely /etc/ssh/sshd_config) and enable X11Forwarding (X11Forwarding yes).
  • login to your server passing the -Y option to ssh (ssh -Y user@server)

You should then be able to start ipython and use %paste.

like image 152
cosarara97 Avatar answered Sep 17 '22 16:09

cosarara97