简体   繁体   English

有没有办法使用 jupyter notebook 在同一个 notebook 中运行不同的 python 版本?

[英]Is there any way to use jupyter notebook to run different python version in the same notebook?

I have added the conda environment to my Jupyter notebook, but the Python version is still 3.8 (Fig 1).我已经在我的 Jupyter notebook 中添加了 conda 环境,但是 Python 版本仍然是 3.8(图 1)。 What I would like to do is to create an environment which contains Python version 3.7 in a Jupyter notebook without starting from a command prompt and running two separate Jupyter notebooks (Fig 2).我想要做的是在 Jupyter 笔记本中创建一个包含 Python 3.7 版的环境,而无需从命令提示符开始并运行两个单独的 Jupyter 笔记本(图 2)。 Is it possible to have simply one jupyter notebook with two separate environments and two different Python versions?是否可以只拥有一个带有两个独立环境和两个不同 Python 版本的 jupyter notebook?

Fig1图。1

在此处输入图片说明

Fig2图2

在此处输入图片说明

Please read this page of the docs for ipykernel.请阅读 ipykernel 文档的这一页

In your environment you want to install only ipykernel (not full Jupyter), and use one of the ipykernel install --name command to register the kernels with Jupyter.在您的环境中要安装的唯一ipykernel(未满Jupyter),并使用一个ipykernel install --name命令Jupyter注册的内核。

If that does not work, use jupyter kernelspec list to see which kernels jupyter see and where.如果这不起作用,请使用jupyter kernelspec list查看 jupyter 看到哪些内核以及在哪里。 A kernelspec is at minimum a kernel.json file in the right place to tell jupyter how to find kernels. kernelspec 至少是一个正确位置的kernel.json文件,用于告诉 jupyter 如何查找内核。

For example I have the following例如我有以下内容

$ cat ~/miniconda3/share/jupyter/kernels/python3/kernel.json
{
 "argv": [
  "~/miniconda3/bin/python",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ],
 "display_name": "Python 3 (ipykernel)",
 "language": "python",
 "metadata": {
  "debugger": true
 }
}

I can use the documentation above, or create the following by hand:我可以使用上面的文档,或手动创建以下内容:

$ cat ~/miniconda3/share/jupyter/kernels/python3.6/kernel.json
{
 "argv": [
  "~/miniconda3/envs/mypython36env/bin/python",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ],
 "display_name": "Python 3.6 !!",
 "language": "python",
 "metadata": {
  "debugger": true
 }
}

and assuming I have the corresponding Python 3.6 env, then I'll get two kernel one of them being Python 3.6并假设我有相应的 Python 3.6 env,那么我将获得两个内核,其中一个是 Python 3.6

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM