【问题标题】:Why the JupyterHub kernel does not align with kernel.json?为什么 JupyterHub 内核与 kernel.json 不一致?
【发布时间】:2018-07-09 22:48:33
【问题描述】:

我正在使用 DockerSpawner 的 SystemUserSpawner (https://github.com/jupyterhub/dockerspawner) 来生成 docker 容器来运行笔记本。

这些容器中的 Jupyter 在 Python 3 上运行,现在我正在尝试向其中添加 Python 2 内核。

RUN pip3.6 --no-cache install \
    jupyterhub==0.9.0 \
    'notebook>=5.0,<=6.0'
...
RUN python2 -m pip install --upgrade pip
RUN python2 -m pip --no-cache install 'ipython<6'
RUN python2 -m pip --no-cache install ipykernel

在此之后,Python 2 内核确实出现在 Jupyter 的列表中 - 正如它应该出现的那样 - 但当我启动它并在“Python 2”笔记本中运行以下命令时,它实际上正在其中运行 Python 3验证“真实”版本:

import sys
print(sys.version)

3.6.5 (default, Apr 10 2018, 17:08:37) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]

查看此容器中可用的内核,一切似乎都很好:

[zoltan.fedor@7a30bb98f7c0 ~]$ jupyter kernelspec list
Available kernels:
  python2    /usr/share/jupyter/kernels/python2
  python3    /usr/share/jupyter/kernels/python3

但实际上内核文件是相同的(除了标题):

vi /usr/share/jupyter/kernels/python2/kernel.json
-----
{
 "display_name": "Python 2",
 "language": "python",
 "argv": [
  "python",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ]
}

还有 Python 3:

vi /usr/share/jupyter/kernels/python3/kernel.json
----
{
 "argv": [
  "python",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ],
 "display_name": "Python 3",
 "language": "python"
}

只需运行“python”即可启动 Python 2 - 它应该:

[zoltan.fedor@7a30bb98f7c0 ~]$ python
Python 2.7.5 (default, Apr 11 2018, 07:36:10) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

那么为什么这两个内核都在其中运行 Python 3?如果有的话,那么我会看到它们都运行 python 2,因为它们使用“python”作为“argv”,它应该启动 python 2.7.5 而不是 3.6.5。

知道我在这里缺少什么吗?

【问题讨论】:

    标签: docker jupyter-notebook


    【解决方案1】:

    原来问题只是我忘了运行以下命令。

    RUN python2 -m ipykernel install
    

    奇怪的是,即使没有这个,python2 kernel.json 也是创建的,它只是没有设置为执行 python 2。 在此之后,python2 内核现在指向:

    $ jupyter kernelspec list
    Available kernels:
      python2    /usr/local/share/jupyter/kernels/python2
      python3    /usr/share/jupyter/kernels/python3
    

    kernel.json 的内容是:

    $ vi /usr/local/share/jupyter/kernels/python2/kernel.json
    ----
    {
     "display_name": "Python 2",
     "language": "python",
     "argv": [
      "/usr/bin/python2",
      "-m",
      "ipykernel_launcher",
      "-f",
      "{connection_file}"
     ]
    }
    

    现在这确实是一个 python 2 内核。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-24
      • 1970-01-01
      • 2020-11-18
      相关资源
      最近更新 更多