本文主要介绍如何在ubuntu 16.04上配置jupyter notebook,便于笔记本等其它终端通过ip直接访问jupyter notebook。
如何安装jupyter notebook就按下不表,在之前的文章中有介绍过,也可以直接安装anaconda。接下来主要讲如何配置jupyter notebook, 下面的步骤可以通过ssh远程登录机器完成。
生成配置文件
$ jupyter notebook --generate-config
生成的配置文件一般在用户目录下:~/.jupyter/jupyter_notebook_config.py
生成密码
此处生成的密码是通过ip地址远程登陆jupyter notebook是的密码。
打开ipython:
In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password: # 输入的登陆密码,谨记
Verify password: # 与上面输入的相同
Out[2]: 'sha1:f29e9c7d01ad:525e......' # 复制密文,后面备用
修改jupyter notebook配置文件
$ vim ~/.jupyter/jupyter_notebook_config.py
修改以下配置项:
c.NotebookApp.ip='*'
c.NotebookApp.password=u'sha1:f29e9c7d01ad:525e......' # 粘贴刚才复制的密文
c.NotebookApp.open_browser=False
c.NotebookApp.port=8888 # 指定端口
启动jupyter notebook
$ jupyter notebook
远程访问
通过http://ip_of_host:8888
即可看到jupyter notebook的登陆界面,可以开始使用了。
可能存在的问题:
- jupyter notebook版本问题导致ip出错
Traceback (most recent call last):
File "/home/user/anaconda3/envs/tensorflow-1.11/lib/python3.6/site-packages/notebook/notebookapp.py", line 869, in _default_allow_remote
addr = ipaddress.ip_address(self.ip)
File "/home/user/anaconda3/envs/tensorflow-1.11/lib/python3.6/ipaddress.py", line 54, in ip_address
address)
ValueError: '' does not appear to be an IPv4 or IPv6 address
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/user/anaconda3/envs/tensorflow-1.11/bin/ipython", line 11, in <module>
sys.exit(start_ipython())
File "/home/user/anaconda3/envs/tensorflow-1.11/lib/python3.6/site-packages/IPython/__init__.py", line 125, in start_ipython
return launch_new_instance(argv=argv, **kwargs)
File "/home/user/anaconda3/envs/tensorflow-1.11/lib/python3.6/site-packages/traitlets/config/application.py", line 657, in launch_instance
app.initialize(argv)
...中间部分省略...
File "/home/user/anaconda3/envs/tensorflow-1.11/lib/python3.6/site-packages/traitlets/traitlets.py", line 535, in get
value = self._validate(obj, dynamic_default())
File "/home/user/anaconda3/envs/tensorflow-1.11/lib/python3.6/site-packages/notebook/notebookapp.py", line 872, in _default_allow_remote
for info in socket.getaddrinfo(self.ip, self.port, 0, socket.SOCK_STREAM):
File "/home/user/anaconda3/envs/tensorflow-1.11/lib/python3.6/socket.py", line 745, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -5] No address associated with hostname
检查版本
jupyter notebook --version
# 5.7.0
当版本为5.7.0时,将配置文件中c.NotebookApp.ip='*'
修改为c.NotebookApp.ip='0.0.0.0'
即可。
后台开启jupyter notebook:
nohup jupyter notebook > /dev/null 2>&1 &
- 网上查资料的时候,其他人也碰到过不少问题,目前自己还没遇到就暂先不总结。(配置时unbuntu主机防火墙已关)。