如何接受来自其他计算机的连接的IPython?(How to accept connections

2019-07-29 08:14发布

我运行IPython的0.12.1在Ubuntu 12.04。 您可以使用笔记本的接口通过运行在浏览器中运行它:

ipython notebook --pylab

配置文件中可以找到~/.config/ipython/profile_default/ 。 似乎每一个内核连接参数放在~/.config/ipython/profile_default/security/kernel-4e424cf4-ba44-441a-824c-c6bce727e585.json 。 下面是这个文件的内容(你开始新内核新文件被创建):

{
  "stdin_port": 54204, 
  "ip": "127.0.0.1", 
  "hb_port": 58090, 
  "key": "2a105dd9-26c5-40c6-901f-a72254d59876", 
  "shell_port": 52155, 
  "iopub_port": 42228
}

这是相当不言自明,但我怎么可以设置将有一个永久配置的服务器,这样我就可以使用笔记本的接口从局域网其他电脑?

Answer 1:

如果您使用的是旧版本的笔记本,下面仍然适用。 对于新版本,请参阅下面的答案。


IPython的文档的有关章节

该笔记本电脑服务器默认本地主机上监听。 如果你希望它是在局域网上的所有计算机上可见,简单地指示它所有接口上听:

ipython notebook --ip='*'

或一个特定的IP到其他计算机上可见:

ipython notebook --ip=192.168.0.123

根据您的环境,它可能是一个好主意, 让HTTPS和密码在外部接口当听。

如果你打算公开服务很多,那么它是一个还不错的主意,以创建一个IPython的配置文件(如ipython profile create nbserver ),并相应编辑配置,因此,所有你需要做的是:

ipython notebook --profile nbserver

加载所有的IP /端口/ SSL /密码设置。



Answer 2:

接受答案/信息是旧版本。 如何让您的新jupyter笔记本电脑远程访问? 我得到了你覆盖

首先,生成一个配置文件,如果你没有它已经:

jupyter notebook --generate-config

注意这个命令的输出,因为它会告诉你,哪里jupyter_notebook_config.py生成文件。 或者,如果你已经拥有了它,它会问你,如果你想用默认的配置覆盖它。 编辑下面一行:

## The IP address the notebook server will listen on.
c.NotebookApp.ip = '0.0.0.0' # Any ip

为了增加安全性,类型在Python / IPython的壳:

from notebook.auth import passwd; passwd()

你会被要求输入并确认密码字符串。 复制字符串的内容,这应该是形式类型的:盐:散列密码。 查找和编辑线路如下:

## Hashed password to use for web authentication.
#  
#  To generate, type in a python/IPython shell:
#  
#    from notebook.auth import passwd; passwd()
#  
#  The string should be of the form type:salt:hashed-password.
c.NotebookApp.password = 'type:salt:the-hashed-password-you-have-generated'

## Forces users to use a password for the Notebook server. This is useful in a
#  multi user environment, for instance when everybody in the LAN can access each
#  other's machine through ssh.
#  
#  In such a case, server the notebook server on localhost is not secure since
#  any user can connect to the notebook server via ssh.
c.NotebookApp.password_required = True

## Set the Access-Control-Allow-Origin header
#  
#  Use '*' to allow any origin to access your server.
#  
#  Takes precedence over allow_origin_pat.
c.NotebookApp.allow_origin = '*'

(重新)启动jupyter笔记本,瞧!



文章来源: How to accept connections for ipython from other computers?