56

我在 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
}

这是不言自明的,但是如何设置具有永久配置的服务器,以便可以使用 LAN 中其他计算机的笔记本接口?

4

2 回答 2

114

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


IPython 文档的相关部分

Notebook 服务器默认侦听 localhost。如果您希望它对 LAN 上的所有机器可见,只需指示它侦听所有接口:

ipython notebook --ip='*'

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

ipython notebook --ip=192.168.0.123

根据您的环境,在侦听外部接口时启用 HTTPS 和密码可能是个好主意。

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

ipython notebook --profile nbserver

加载所有 ip/port/ssl/password 设置。

于 2012-05-10T21:11:33.380 回答
21

接受的答案/信息适用于旧版本。如何启用对新的 jupyter notebook 的远程访问?我得到了你的保障

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

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()

您将被要求输入并确认密码字符串。复制字符串的内容,其格式应为 type: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 notebook,瞧!

于 2018-02-09T22:30:01.770 回答