简体   繁体   English

使用SSH +屏幕远程启动IPython,然后分离并注销

[英]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. 我的局域网上有一台计算机,我想运行一台IPython Notebook服务器。 The computer is headless, so I can only access this computer using SSH. 计算机是无头的,所以我只能使用SSH访问这台计算机。 I tried to start IPython Notebook through screen, then detach, but the kernel restarts with X server errors. 我尝试通过屏幕启动IPython Notebook,然后分离,但内核重新启动X服务器错误。

Specifically, I did the following: 具体来说,我做了以下事情:

  • SSH into remote box: ssh -X 1.1.1.1 SSH进入远程框: ssh -X 1.1.1.1
  • Start or re-attach to last screen: screen -RD 启动或重新连接到最后一个屏幕: screen -RD
  • Start Notebook ipython notebook 启动Notebook ipython notebook
  • Detach and logout: ctrl-ad , exit 分离和注销: ctrl-adexit

The remote Notebook server works fine, until I log out, and then try and create a matplotlib plot. 远程笔记本服务器工作正常,直到我退出,然后尝试创建一个matplotlib图。 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. 由于缺少X资源,似乎笔记本电脑无法在我注销后立即进行绘图。 Does anyone have a solution to this? 有人有解决方案吗?

Ipython is creating your plots (or any other X-graphics such as traitsui UI elements) in the X session you created with ssh -X . Ipython在您使用ssh -X创建的X会话中创建绘图(或任何其他X图形,如traitsui UI元素)。 When you log out, the ssh tunnel closes along with that X session, thus the errors. 当您注销时,ssh隧道将与该X会话一起关闭,从而导致错误。 Without the ssh tunnel, the plots have no way to get to you. 没有ssh隧道,情节无法找到你。

Assuming you don't have a physical terminal on the server with which to see the plots etc.., you can see matplotlib plots by telling IPython notebook to show the plots inline. 假设您在服务器上没有物理终端来查看图表等,您可以通过告诉IPython笔记本显示内联图来查看matplotlib图。 Note that with the current version of ipython, the plots are static png's. 请注意,对于当前版本的ipython,这些图是静态png。 I'm not sure if traitsui has a way to do something like that? 我不确定traitsui是否有办法做那样的事情?

There's a few ways to do this: 有几种方法可以做到这一点:

  • import the pylab module with %pylab inline 使用%pylab inline导入pylab模块
  • import matplotlib with %matplotlib inline (not sure if this is available in older versions) 使用%matplotlib inline导入matplotlib(不确定这是否在旧版本中可用)
  • run ipython with ipython notebook --pylab=inline ipython notebook --pylab=inline运行ipython ipython notebook --pylab=inline
  • configure ipython to use pylab inline always: run ipython profile create , then look for "inline" in ipython_notebook_config.py , which is in your ipython profile directory - ~/.config/ipython/profile_default/ on Ubuntu. 配置ipython总是使用pylab inline:运行ipython profile create ,然后在ipython_notebook_config.py找到“inline”,它位于你的ipython配置文件目录中-- ~/.config/ipython/profile_default/在Ubuntu上。

It appears as though these kernel restarts only occur when I import traitsui modules in a notebook. 看起来好像这些内核重启只发生在我在笔记本中导入traitsui模块时。 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, 解决方案是导入任何traitsui模块之前更改traitsui的后端,

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. 编辑:traitsui功能没有在ssh中使用,它只是更大模块的一部分。

  • SSH into remote box: ssh -X 1.1.1.1 SSH进入远程框: ssh -X 1.1.1.1
  • Start screen: screen -S ipython_process 开始屏幕: screen -S ipython_process
  • Start Notebook: ipython notebook --profile=nbserver 启动Notebook: ipython notebook --profile=nbserver
  • Detach: ctrl-ad 分离: ctrl-ad

Enjoy remotely via browser on port 8888 通过端口8888上的浏览器远程享受

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM