如何使用其他版本的Python运行Jupyter Notebook?

我希望能够在Jupyter Notebook中同时运行Python 3.8(当前版本)和Python 3.7。我知道从虚拟环境创建不同的IPython内核是这样的。 因此,我下载了Python 3.7,并将其本地安装在主目录中。使用此python二进制文件通过以下方式创建虚拟环境

> virtualenv -p ~/Python3.7/bin/python3 py37
> source py37/bin/activate

This works perfectly and gives 'Python 3.7' correctly on checking with python --version and sys.version. Then for creating IPython kernel,

(py37) > ipython kernel install --user --name py37 --display-name "Python 3.7"
(py37) > jupyter notebook

This also runs without error and the kernel can be confirmed to be added in the Notebook. However it does not run Python 3.7 like the virtual environment, but Python 3.8 like the default kernel. (confirmed with sys.version)

I checked ~/.local/share/jupyter/kernels/py37/kernel.json and saw its contents as

{
 "argv": [
  "/usr/bin/python3",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ],
 "display_name": "Python 3.7",
 "language": "python"

So naturally I tried editing the /usr/bin/python3 to point to my Python 3.7 binary file path that is ~/Python3.7/bin/python3, but then even the kernel doesn't work properly in the notebook.

我该怎么办?

注意:我使用Arch Linux,所以我通过pacman安装了jupyter,virtualenv,...,而不是Arch中推荐的pip。

评论