设置 Python 虚拟环境启动 Jupyter Notebook gaierror: [Errno -2] Name or service not known

Posted

技术标签:

【中文标题】设置 Python 虚拟环境启动 Jupyter Notebook gaierror: [Errno -2] Name or service not known【英文标题】:Setting up Python Virtual Env Initiating Jupyter Notebook gaierror: [Errno -2] Name or service not known 【发布时间】:2018-11-09 20:51:33 【问题描述】:

当我尝试在虚拟环境中启动 Jupyter 笔记本时,我收到以下错误 - .gaierror: [Errno -2] Name or service not known

虚拟环境 -wget https://pypi.python.org/packages/source/v/virtualenv/virtualenv-12.0.7.tar.gz

Traceback (most recent call last):
  File "/home/vraja/pyspark/bin/jupyter-notebook", line 11, in <module>
    sys.exit(main())
  File "/home/vraja/pyspark/lib/python2.7/site- 
    packages/jupyter_core/application.py", line 266, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/home/vraja/pyspark/lib/python2.7/site- 
   packages/traitlets/config/application.py", line 657, in launch_instance
    app.initialize(argv)
  File "<decorator-gen-7>", line 2, in initialize
  File "/home/vraja/pyspark/lib/python2.7/site- 
  packages/traitlets/config/application.py", line 87, in catch_config_error
    return method(app, *args, **kwargs)
  File "/home/vraja/pyspark/lib/python2.7/site- 
  packages/notebook/notebookapp.py", line 1629, in initialize
    self.init_webapp()
  File "/home/vraja/pyspark/lib/python2.7/site- 
  packages/notebook/notebookapp.py", line 1379, in init_webapp
    self.jinja_environment_options,
  File "/home/vraja/pyspark/lib/python2.7/site- 
  packages/notebook/notebookapp.py", line 158, in __init__
    default_url, settings_overrides, jinja_env_options)
  File "/home/vraja/pyspark/lib/python2.7/site- 
  packages/notebook/notebookapp.py", line 251, in init_settings
    allow_remote_access=jupyter_app.allow_remote_access,
  File "/home/vraja/pyspark/lib/python2.7/site- 
  packages/traitlets/traitlets.py", line 556, in __get__
    return self.get(obj, cls)
  File "/home/vraja/pyspark/lib/python2.7/site- 
  packages/traitlets/traitlets.py", line 535, in get
    value = self._validate(obj, dynamic_default())
  File "/home/vraja/pyspark/lib/python2.7/site- 
  packages/notebook/notebookapp.py", line 872, in _default_allow_remote
     for info in socket.getaddrinfo(self.ip, self.port, 0, 
     socket.SOCK_STREAM):
     socket.gaierror: [Errno -2] Name or service not known
(pyspark)-sh-4.1$

【问题讨论】:

【参考方案1】:

您是否设置了配置文件变量?..

请在配置文件中添加以下环境变量。

导出 PYSPARK_DRIVER_PYTHON=jupyter

导出 PYSPARK_DRIVER_PYTHON_OPTS='notebook'

【讨论】:

是的,我确实设置了它们 点击此链接,blog.sicara.com/… 根据github.com/jupyterlab/jupyterlab/issues/5410(Pazitos10 评论)将 NotebookApp.ip='*' 更改为 Changed NotebookApp.ip='0.0.0.0'【参考方案2】:

根据https://github.com/jupyterlab/jupyterlab/issues/5410(Pazitos10 评论)将 NotebookApp.ip='*' 更改为 Changed NotebookApp.ip='0.0.0.0'

【讨论】:

以上是关于设置 Python 虚拟环境启动 Jupyter Notebook gaierror: [Errno -2] Name or service not known的主要内容,如果未能解决你的问题,请参考以下文章

Python学习-配置jupyter和虚拟环境

jupyter notebook添加Anaconda虚拟环境的python kernel

在jupyter中配置python3

图解Windows10下如何更换Jupyter Notebook 内核Python版本(切换原始的python环境)

jupyter中添加conda环境

jupyter多个虚拟环境间切换