Search code examples
pythonsshipythonenthoughtjupyter-notebook

Start IPython remotely using SSH+screen, then detach and log out


I have a computer on my LAN that I would like to run an IPython Notebook server on. The computer is headless, so I can only access this computer using SSH. I tried to start IPython Notebook through screen, then detach, but the kernel restarts with X server errors.

Specifically, I did the following:

  • SSH into remote box: ssh -X 1.1.1.1
  • Start or re-attach to last screen: screen -RD
  • Start Notebook ipython notebook
  • Detach and logout: ctrl-a-d, exit

The remote Notebook server works fine, until I log out, and then try and create a matplotlib plot. At which time I get

Kernel Restarting
The kernel appears to have died. It will restart automatically.

from the client's web-browser, and

-c: cannot connect to X server localhost:10.0
2013-08-01 10:28:48.072 [NotebookApp] KernelRestarter: restarting kernel (1/5)
WARNING:root:kernel 6e0f5395-6ba7-44c8-912f-1e736dd66517 restarted

on the server.

It appears as though the Notebook can't plot as soon as I log out due to lack of X-resources. Does anyone have a solution to this?


Solution

  • It appears as though these kernel restarts only occur when I import traitsui modules in a notebook. Specially, the following imports cause the error.

    from traitsui.api import *
    from traitsui.menu import *
    

    The solution is to change the backend for traitsui, before importing any traitsui modules,

    from traits.etsconfig.api import ETSConfig
    ETSConfig.toolkit = 'null'
    

    EDIT: the traitsui functionality was not being used across ssh, it was just part of a larger module.