如何在 jupyter 上将 python 3.6 内核与 3.5 一起添加

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43759610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 23:23:24  来源:igfitidea点击:

How to add python 3.6 kernel alongside 3.5 on jupyter

pythonipythonjupyter

提问by fccoelho

I am trying to test some code on Python 3.6 but my system default python version is python 3.5 I have installed python 3.6 and have tried to follow the jupyter documentation to install a new python kernel

我正在尝试在 Python 3.6 上测试一些代码,但我的系统默认 python 版本是 python 3.5 我已经安装了 python 3.6 并尝试按照 jupyter 文档安装新的 python 内核

python3.6 -m pip install ipykernel
python3.6 -m ipykernel install --user

But it didn't work since it continues to show a single kernel in the menu: Python3

但它不起作用,因为它继续在菜单中显示单个内核: Python3

Has anyone managed to have both 3.5 and 3.6 in the same jupyter installation?

有没有人设法在同一个 jupyter 安装中同时安装 3.5 和 3.6?

回答by Lauren

one option is to create a kernel that you can use in jupyter notebook. enter image description here

一种选择是创建一个可以在 jupyter notebook 中使用的内核。 在此处输入图片说明

you can do this inside the virtual environment:

您可以在虚拟环境中执行此操作:

  1. Open up your terminal and enter the following line by line

    virtualenv -p python3.6 py_36_env

    source py_36_env/bin/activate

    pip install ipykernel

    python -m ipykernel install --user --name=py_36_env

    jupyter notebook

  2. Then in jupyter notebook you can select the 3.6 environment (py_36_env) from the 'New' drop down menu shown above or from the 'Kernel' drop down menu within a given jupyter notebook.

  1. 打开终端并逐行输入以下内容

    virtualenv -p python3.6 py_36_env

    source py_36_env/bin/activate

    pip install ipykernel

    python -m ipykernel install --user --name=py_36_env

    jupyter notebook

  2. 然后在 jupyter notebook 中,您可以py_36_env从上面显示的“新建”下拉菜单中或从给定 jupyter 笔记本中的“内核”下拉菜单中选择 3.6 环境 ( )。

回答by user3274034

Steps to install Python 3.6 in Windows

在 Windows 中安装 Python 3.6 的步骤

  1. Open command prompt
  2. conda install ipykernel
  3. conda create -n Python3.6Test python=3.6
  4. Activate Python3.6Test
  5. pip install ipykernel
  6. python -m ipykernel install --name Python3.6Test
  1. 打开命令提示符
  2. conda install ipykernel
  3. conda create -n Python3.6Test python=3.6
  4. 激活 Python3.6Test
  5. pip install ipykernel
  6. python -m ipykernel install --name Python3.6Test

Here you go with 3.6 C:\ProgramData\jupyter\kernels\Python3.6Test

在这里你使用 3.6 C:\ProgramData\jupyter\kernels\Python3.6Test

Now open Jupitor Notebook and see, you will get the Python3.6Test option

现在打开 Jupitor Notebook 看看,你会得到 Python3.6Test 选项

回答by Nils Werner

You should create a virtualenv for each Python version you are using. Create one for Python 3.5:

您应该为正在使用的每个 Python 版本创建一个 virtualenv。为 Python 3.5 创建一个:

virtualenv -p /usr/bin/python3.5 py35
source py35/bin/activate
pip install jupyter
jupyter               # Jupyter running Python 3.5
deactivate           # Leave virtualenv

And create one for Python 3.6:

并为 Python 3.6 创建一个:

virtualenv -p /usr/bin/python3.6 py36
source py36/bin/activate
pip install jupyter
jupyter               # Jupyter running Python 3.6

回答by Yogesh

Following worked for me:

以下为我工作:

Commands are executed in Jupyter Notebook (OS: Ubuntu 16.04 LTS)

命令在 Jupyter Notebook 中执行(操作系统:Ubuntu 16.04 LTS)

Upgrade pip:

升级点:

!pip install --upgrade pip

Install virtual environment:

安装虚拟环境:

!pip install virtualenv

Select version of Python you want to use in new environment:

选择要在新环境中使用的 Python 版本:

I wanted to create an environment with Python version 3.6 Naming it as Python_3_6:

我想用 Python 3.6 版创建一个环境,将其命名为 Python_3_6:

!virtualenv -p python3.6 Python_3_6

After execution, this will create a folder with the same name in the current working directory (i.e. the location where Jupyter notebook is present)

执行后,这将在当前工作目录(即 Jupyter notebook 所在的位置)中创建一个同名文件夹

Create a new option with the name of the created environment

使用创建的环境的名称创建一个新选项

And finally, run the following command:

最后,运行以下命令:

!python -m ipykernel install --user --name=Python_3_6

This will create a new option with the name Python_3_6 in the menu from where we create a new notebook.

这将在我们创建新笔记本的菜单中创建一个名为 Python_3_6 的新选项。

NOTE: One can run above commands from the terminal as well just don't use '!' before the commands.

注意:也可以从终端运行上面的命令,只是不要使用“!” 命令之前。

回答by azeldes

This is an old question, but like some commenters here I wanted to change the defaultjupyter completely without using a venv. It seems jupyter keeps this in a json file called kernel.json:

这是一个老问题,但就像这里的一些评论者一样,我想在不使用 venv的情况下完全更改默认的 jupyter。似乎 jupyter 将它保存在一个名为kernel.json的 json 文件中:

{
 "display_name": "Python 3",
 "language": "python",
 "argv": [
  "/path/to/some/python",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ]
}

There may be several paths containing this file which are searched in order. To find out what they are on your machine, run:

可能有多个包含此文件的路径会按顺序搜索。要找出它们在您的机器上的内容,请运行:

ipython kernel install --prefix tmp

ipython will throw a warning that the config file is being created in tmp and might not be found, but it will also output the paths it uses to find kernel.json, which you can then edit manually.

ipython 会抛出一个警告,指出配置文件正在 tmp 中创建并且可能找不到,但它也会输出它用来查找 kernel.json 的路径,然后您可以手动编辑它。