如何从其他计算机接受ipython的连接?

问题描述 投票:50回答:2

我在Ubuntu 12.04上运行ipython 0.12.1。您可以使用笔记本界面在浏览器中运行它:

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
}

它是相当不言自明的,但我如何设置一个具有永久配置的服务器,所以我可以使用局域网中其他计算机的笔记本界面?

configuration ipython
2个回答
110
投票

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


Relevant section of the IPython docs

Notebook服务器默认侦听localhost。如果您希望LAN上的所有计算机都可以看到它,只需指示它监听所有接口:

ipython notebook --ip='*'

或者其他机器可见的特定IP:

ipython notebook --ip=192.168.0.123

根据您的环境,在监听外部接口时,enable HTTPS and a password可能是个好主意。

如果你计划公开服务,那么创建一个IPython配置文件(例如ipython profile create nbserver)并相应地编辑配置也是一个好主意,所以你需要做的就是:

ipython notebook --profile nbserver

加载所有ip / port / ssl /密码设置。


14
投票

The accepted answer/information is for an old version. How to enable remote access to your new jupyter notebook? I got you covered

首先,如果您还没有配置文件,请生成配置文件:

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 shell:

from notebook.auth import passwd; passwd()

系统将要求您输入并确认密码字符串。复制字符串的内容,其格式应为:salt:hashed-password。查找和编辑行如下:

## 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笔记本,瞧!

© www.soinside.com 2019 - 2024. All rights reserved.