14

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.

Community
  • 1
  • 1
measureallthethings
  • 1,102
  • 10
  • 26
  • Another variation when trying to use magic paste function is `TclError: couldn't connect to display "localhost:10.0"` – measureallthethings Mar 06 '15 at 19:20
  • Concerning the localhost error...tried this but still can't get magic paste to work http://stackoverflow.com/questions/2443702/problem-running-python-matplotlib-in-background-after-ending-ssh-session – measureallthethings Mar 09 '15 at 16:25
  • This appears to be an IPython 3.0 bug, FWIW I am having he same problem on an ARM server – JCR000 Mar 16 '15 at 15:53

1 Answers1

7

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.

cosarara97
  • 115
  • 2
  • 5