首页 > 解决方案 > Jupyter 与 Python 版本混合使用。内核使用 python 3.x 而不是 2.x

问题描述

我有一个用 Python 2.7 编写的 ipynb 笔记本,所以我将内核更改为使用 Python2。

即使更改了内核版本,它仍然明显使用 Python3 而不是 Python2。这是我得到的错误之一,显然来自 Python3:

print 'blah blah'
                ^
SyntaxError: invalid syntax

笔记本元数据还显示"version": "3.6.9"

{
  "kernelspec": {
    "name": "python2",
    "display_name": "Python 2",
    "language": "python"
  },
  "language_info": {
    "name": "python",
    "version": "3.6.9",
    "mimetype": "text/x-python",
    "codemirror_mode": {
      "name": "ipython",
      "version": 3
    },
    "pygments_lexer": "ipython3",
    "nbconvert_exporter": "python",
    "file_extension": ".py"
  }
}

我试图编辑元数据,但这似乎没有任何影响。

这是我在该主题上找到的唯一相关资源:https ://github.com/jupyter/notebook/issues/1689

版本信息:

jupyter core     : 4.6.3
jupyter-notebook : 6.0.3
qtconsole        : 4.3.1
ipython          : 5.5.0
ipykernel        : 4.8.2
jupyter client   : 6.1.3
jupyter lab      : not installed
nbconvert        : 5.6.1
ipywidgets       : 7.5.1
nbformat         : 4.4.0
traitlets        : 4.3.2

标签: python-3.xlinuxjupyter-notebookipythonpython-2.x

解决方案


推荐阅读