安装配置远程jupyter notebook(原ipython notebook)

来源:互联网 发布:淘宝主图大小尺寸像素 编辑:程序博客网 时间:2024/06/06 01:59

在新版本的ipython中,将逐步不再使用ipython notebook这个名字,现在已经把通过浏览器远程使用notebook迁移到了jupeter notebook底下。如果继续按照以前的办法配置远程ipython notebook,多半会发现找不到给ipython notebook服务器创建的配置文件
/profile_nbserver/ipython_notebook_config.py。
下面是jupyter notebook远程服务器的配置教程。

1.创建登陆密码

先在服务器端启动远程ipython,生成自定义密码的sha1

In [1]: from IPython.lib import passwdIn [2]: passwd()Enter password:Verify password:Out[2]: ‘sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed‘... prompt'''

此时输入密码和确认密码,第六步远程登陆就是用这个密码。同时牢记sha1,下面的配置要用到。

2.创建自签名证书

使用openssl创建一个自签名证书,由于是自签名所以浏览器会提示警告,选择信任exception即可。如果不想引起警告,需具备合格证compliant certificate,可参照tutorial

$ openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem

记住mycert.pem的位置,一会要用到,可通过pwd查看

3.创建jupyter notebook服务器

jupyter notebook --generate-config

命令行会有输出,告诉你生成的文件在哪里.
默认位置在~/.jupyter/jupyter_notebook_config.py
此时可以将 mycert.pem 证书移到jupyter notebook的文件夹,将相关的东西放在一起。

mv mycert.pem .jupyter

4.修改配置文件

生成的配置文件在 /home/yourname/.jupyter/jupyter_notebook_config.py
打开配置文件,把下面cerfile的路径以及password里边sha1后边的内容替换为自己的,然后粘贴到配置文件的最底下,保存退出。注意使用英文输入法复制粘贴,要不英文单引号对”会被替换为中文单引号对‘’。

c = get_config()# Notebook configc.NotebookApp.pylab = 'enable'  # if you want plotting support alwaysc.NotebookApp.certfile = u'/home/yourname/.jupyter/mycert.pem'c.NotebookApp.ip = '*'c.NotebookApp.open_browser = Falsec.NotebookApp.password = u'sha1:42dd2962e4eb:4e258d7a934d8971e4b26b460ab27276a9d082b0'# It's a good idea to put it on a known, fixed portc.NotebookApp.port = 9999

5.启动jupyter notebook服务器

 jupyter notebook --certfile=mycert.pem

其中,上面的mycert.pem要至少写明相对路径,一个不错的办法是在你的项目底下对mycert.pem建立一个硬链接(防止误删除),这样就不用每次都输入路径了。

然后看到下面输出

 The Jupyter Notebook is running at: https://[all ip addresses on your system]:9999/

6.远程连接jupyter notebook

以上操作都是在服务器上的操作,现在打开浏览器,输入
https://192.168.56.101:9999
此时要求输入密码,这个密码就是刚才创建sha1时输入的密码(不是sha1)。

其他的和普通的jupyter notebook一样的操作了。
注意,这里192.168.56.101是我服务器上的ubuntu开启的地址,请换成你的远程地址。

7.迁移以前的ipython notebook服务器配置文件

如果你需要迁移以前的ipython notebook配置文件,可以使用命令

jupyter migrate

这样配置文件会被转移到~/.jupyter文件夹底下。

参考:
-http://stackoverflow.com/questions/31962862/ipython-ipython-notebook-config-py-missing
-http://blog.csdn.net/suzyu12345/article/details/51037905
-http://jupyter.readthedocs.io/en/latest/migrating.html

0 0
原创粉丝点击