启动 Jupyter Notebook 遇到 socket.gaierror

默认配置的情况下,无法启动 Jupyter notebook,报错如下:

1
socket.gaierror: [Errno -2] Name or service not known

官方文档中的提到只需要更改 ~/.jupyter/jupyter_notebook_config.py 文件中的 c.NotebookApp.ip 即可实现外部访问:

1
2
# Set ip to '*' to bind on all interfaces (ips) for the public server
c.NotebookApp.ip = '*'

但在较新的版本的 Jupyter(大概5.6.0以上)中,如果不做其他改动,便会报错。解决办法有两种:

  1. c.NotebookApp.ip 改为 0.0.0.0
  2. 打开远程访问权限,将 c.NotebookApp.allow_remote_access 改为 True

相关链接: