难度 运行 jupyter notebook Python2

Difficulty running jupyter notebook on Python2

我的电脑上安装了 Python 2 (2.7.14) 和 Python 3 (3.6.4)
(Linux rajarshi-x550cc 4.15.10-300.fc27.x86_64 #1 SMP Thu Mar 15 17:13:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux)

我也安装了Jupyter Notebook。当我在 Jupyter Notebook 上 运行 一个新内核时,无论我选择 运行 Python-2 内核还是 Python-3 内核,只有 Python -3 内核是 运行。我用 print(sys.version).

检查过这个

我在 Whosebug 上得到了几个很好的答案,但是 none 其中对我有用。我在 /usr/share/jupyter/kernels/python2 的 Jupyter 库中创建了一个 JSON 文件,代码如下:

{
 "display_name": "Python 2", 
 "language": "python", 
 "argv": [
  "python", 
  "-m", 
  "ipykernel_launcher", 
  "-f", 
  "{connection_file}"
 ]
}

但没有明显差异。

然后我从 Python 3 中卸载了 Jupyter,如下所示: python3 -m pip uninstall jupyter 但是 Jupyter 仍然存在,它仍然只识别 Python 3.

老实说,我已经无计可施了。我应该完全删除 Python 3 吗?

您可以使用ipykernel在同一笔记本环境中注册不同版本的python。

有关详细信息,请参阅以下文档 https://ipython.readthedocs.io/en/latest/install/kernel_install.html#kernels-for-python-2-and-3

如果我是你,我会完全卸载python然后继续:

  1. 使用 python 3.6 安装 anaconda
  2. 使用python2.7

    创建虚拟环境

    conda create -n python27 python=2.7 anaconda

  3. 如果我想要 python 3.6 的 jupyter notebook,我会 运行 jupyter notebook

  4. 对于 python 2.7 的 jupyter notebook,我将 activate python27 然后 jupyter notebook。这将启动带有 python 2.7
  5. 的笔记本