Jupyter Notebook远程访问配置中容易犯错的一点

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/luoleeming/article/details/78538984
随便百度一下Jupyter Notebook远程访问如何配置,都能找到一大堆的教程,内容基本前篇一律,看似只要按其配置,便绝无配错的可能。但我认为这些教程中往往忽略了对配置项的必要解释,例如c.NotebookApp.ip这行,其配置的其实是允许访问的IP地址,类似于防火墙的设置,也就是说''中应填写客户端IP地址,如果允许任何客户端访问,那就是'*'

c.NotebookApp.ip='*'

我最初误以为这里是要配置服务器的IP地址,结果就遇到启动Jupyter Notebook时出现如下报错。

root@Liming-AI:~/.jupyter# jupyter notebook
[I 11:14:51.664 NotebookApp] Writing notebook server cookie secret to /run/user/0/jupyter/notebook_cookie_secret
Traceback (most recent call last):
  File "/root/anaconda3/bin/jupyter-notebook", line 11, in <module>
    sys.exit(main())
  File "/root/anaconda3/lib/python3.6/site-packages/jupyter_core/application.py", line 267, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/root/anaconda3/lib/python3.6/site-packages/traitlets/config/application.py", line 657, in launch_instance
    app.initialize(argv)
  File "<decorator-gen-7>", line 2, in initialize
  File "/root/anaconda3/lib/python3.6/site-packages/traitlets/config/application.py", line 87, in catch_config_error
    return method(app, *args, **kwargs)
  File "/root/anaconda3/lib/python3.6/site-packages/notebook/notebookapp.py", line 1296, in initialize
    self.init_webapp()
  File "/root/anaconda3/lib/python3.6/site-packages/notebook/notebookapp.py", line 1120, in init_webapp
    self.http_server.listen(port, self.ip)
  File "/root/anaconda3/lib/python3.6/site-packages/tornado/tcpserver.py", line 142, in listen
    sockets = bind_sockets(port, address=address)
  File "/root/anaconda3/lib/python3.6/site-packages/tornado/netutil.py", line 197, in bind_sockets
    sock.bind(sockaddr)
OSError: [Errno 99] Cannot assign requested address
去百度上搜索,大家给的解决方案一般就是在jupyter notebook后面加上 --ip=127.0.0.1. 这个回答其实很扯淡——是能运行了,但这样只能在服务器上运行,而不能在任何客户端运行!而且如果要这么指定的话,你甚至根本就不用配置jupyter_notebook_config.py。
其实问题就出在前述c.NotebookApp.ip的设定上,所以对于网上搜来的教程,还是要搞清楚每个配置的意义究竟是什么,而只是照抄。
展开阅读全文

没有更多推荐了,返回首页