首页 文章

如何将python3内核添加到jupyter(IPython)

提问于
浏览
237

我的 Jupyter 笔记本安装了 python 2 内核 . 我不懂为什么 . 我做安装时可能搞砸了 . 我已经安装了 python 3 . 如何将其添加到 Jupyter ?下面是 python3 -m install jupyter 默认 Jupyter 与浏览器打开的截图 jupyter notebook 如下所示:
enter image description here

18 回答

  • 192

    在Ubuntu 14.04上,我不得不使用以前的答案组合 .

    首先,安装 pip3 apt-get install python-pip3

    然后用 pip3 安装jupyter pip3 install jupyter

    然后使用 ipython3 安装内核 ipython3 kernel install

  • 4

    这是我找到的Windows /非命令行方法,它对我有用:找到存储内核文件的文件夹(在我的机器上 - C:\ ProgramData \ jupyter \ kernels - 注意ProgramData是一个隐藏文件夹),创建一个复制现有内核的文件夹,更改名称并编辑其中的json文件以指向新内核的目录 . 在这个json中你还可以编辑ipython中显示的内核名称(例如,如果你因某些原因需要进一步区分,你可以指定2.7.9而不是python 2) .

  • 5

    我很确定你所要做的就是跑步

    pip3安装jupyter

  • 3

    对于当前的Python启动器

    如果安装了Py3但默认为py2

    py -3 -m pip install ipykernel
    py -3 -m ipykernel install --user
    

    如果安装了Py2但默认为py3

    py -2 -m pip install ipykernel
    py -2 -m ipykernel install --user
    
  • 37

    我有Python 2.7,并希望能够在Jupyter内部切换到Python 3 .

    这些步骤适用于Windows Anaconda命令提示符:

    conda update conda
    conda create -n py33 python=3.3 anaconda
    activate py33
    ipython kernelspec install-self
    deactivate
    

    现在,在使用Python2.7的常用命令打开ipython笔记本之后,在创建新笔记本时也可以使用Python3.3 .

  • 12

    for recent versions of jupyter/ipython :使用 jupyter kernelspec

    列出当前内核

    $ jupyter kernelspec list
    Available kernels:
      python2    .../Jupyter/kernels/python2
      python3    .../Jupyter/kernels/python3
    

    在我的情况下,python3内核设置被破坏,因为py3.5链接不再存在,取而代之的是py3.6

    添加/删除内核

    Remove:

    $ jupyter kernelspec uninstall python3
    

    Add a new one:

    $ jupyter kernelspec install /usr/local/Cellar/python3/3.6.1/bin/
    

    要查找该文件夹,您可以使用 which PYTHON 例如 which python3.6 (如果您使用的是pyenv,则为 pyenv which python3.6 !) . 然后

    ls -la `which python3.6`
    

    将显示可执行文件的位置 .

    List again:

    $ jupyter kernelspec list
    Available kernels:
      python3    /usr/local/lib/python3.6/site-packages/ipykernel/resources
      python2    /Users/stefano/Library/Jupyter/kernels/python2
    

    Doc:https://jupyter-client.readthedocs.io/en/latest/kernels.html#kernelspecs

    详情

    可用的内核列在Jupyter DATA DIRECTORY的 kernels 文件夹下(有关详细信息,请参阅http://jupyter.readthedocs.io/en/latest/projects/jupyter-directories.html) .

    例如在macosx上 /Users/YOURUSERNAME/Library/Jupyter/kernels/

    内核简单地由 kernel.json 文件描述,例如 . 为 /Users/me/Library/Jupyter/kernels/python3/kernel.json

    {
     "argv": [
      "/usr/local/opt/python3/bin/python3.5",
      "-m",
      "ipykernel",
      "-f",
      "{connection_file}"
     ],
     "language": "python",
     "display_name": "Python 3"
    }
    

    而不是手动操作,您可以使用 kernelspec 命令(如上所述) . 它以前通过ipython现在通过jupyter(http://ipython.readthedocs.io/en/stable/install/kernel_install.html#kernels-for-different-environments - https://jupyter-client.readthedocs.io/en/latest/kernels.html#kernelspecs)获得 .

    $ jupyter kernelspec help
    Manage Jupyter kernel specifications.
    
    Subcommands
    -----------
    
    Subcommands are launched as `jupyter kernelspec cmd [args]`. For information on
    using subcommand 'cmd', do: `jupyter kernelspec cmd -h`.
    
    list
        List installed kernel specifications.
    install
        Install a kernel specification directory.
    uninstall
        Alias for remove
    remove
        Remove one or more Jupyter kernelspecs by name.
    install-self
        [DEPRECATED] Install the IPython kernel spec directory for this Python.
    
    To see all available configurables, use `--help-all`
    

    其他语言的内核

    顺便说一句,与这个问题并没有严格的关系,但是还有很多其他内核可供使用... https://github.com/jupyter/jupyter/wiki/Jupyter-kernels

  • 26

    以下命令适用于我,在macOS Sierra(10.12.3)

    python3 -m pip install ipykernel
    python3 -m ipykernel install --user
    

    用jupyter kernelspec列表检查它可用的内核:python3 / Users / admin / Library / Jupyter / kernels / python3 python2 / anaconda2 / share / jupyter / kernels / python2

  • 18
    sudo apt-get install python3-pip python3-dev
    pip3 install -U jupyter
    
  • 90

    确保安装了 ipykernel 并使用 ipython kernel install 将kernelspec放在python2的正确位置 . 然后是 ipython3 kernel install for Python3 . 现在,您应该能够在2个内核之间进行选择,无论您使用 jupyter notebookipython notebook 还是 ipython3 notebook (后两个都已弃用) .

    请注意,如果要为特定的Python可执行文件安装,可以使用以下技巧:

    path/to/python -m ipykernel install <options>
    

    这适用于使用环境(venv,conda,...)和 <options> 让你命名你的内核(见 --help ) . 所以你可以做到

    conda create -n py36-test python=3.6
    source activate py36-test
    python -m ipykernel install --name py36-test
    source deactivate
    

    现在,您在下拉菜单中获得了一个名为 py36-test 的内核,以及其他内核 .

    请参阅Using both Python 2.x and Python 3.x in IPython Notebook,其中包含更多最新信息 .

  • 35
    • 用Python2获得ipython笔记本(在Windows7上)

    • pip install -U jupyter 升级到Jupyter

    • 安装Python3

    • 再次使用 pip3 install jupyter 安装Jupyter

    • 使用 ipython3 kernelspec install-self 安装Python3内核

    • 我终于有了2个工作内核 .

    great results

  • 7

    打开终端(或窗口的cmd),然后运行以下命令:(在窗口中,在第二行中删除“source” . )

    conda create -n py35 python=3.5
    source activate py35
    conda install notebook ipykernel
    ipython kernel install --user --name=python3.5
    

    我尝试了一些方法,但它不起作用,然后我发现了这种方式 . 它与我合作 . 希望它可以帮助 .

  • 0

    在ElementaryOS Freya(基于Ubuntu 14.04)中,没有其他答案立即为我工作;我得到了

    [TerminalIPythonApp]警告|找不到档案:'kernelspec'

    在_329920的答案下,quickbug描述的错误 . 我不得不先做:

    sudo apt-get install pip3 ,然后

    sudo pip3 install ipython[all]

    此时,您可以运行Matt建议的命令;即: ipython kernelspec install-selfipython3 kernelspec install-self

    现在,当我启动 ipython notebook 然后打开笔记本时,我可以从内核菜单中选择Python 3内核 .

  • 0

    这在Ubuntu 16.04上对我有用:

    python2 -m pip install ipykernel
    python2 -m ipykernel install --user
    
    python3 -m pip install ipykernel
    python3 -m ipykernel install --user
    

    参考文档:
    Kernels for Python 2 and 3 . 安装IPython内核 - IPython文档 .

  • 3

    我在macOS El Capitan上成功安装了python3内核(ipython版本:4.1.0)使用以下命令 .

    python3 -m pip install ipykernel
    python3 -m ipykernel install --user
    

    您可以使用 jupyter kernelspec list 查看所有已安装的内核 .

    更多信息可用here

  • 5

    我设法安装除Python2之外的Python3内核 . 这是我做的方式:

    最新的工作链接可以在here找到 .

    实际代码是:

    ! mkdir -p ~/.ipython/kernels/python3
    %%file ~/.ipython/kernels/python3/kernel.json
    
    {
     "display_name": "IPython (Python 3)", 
     "language": "python", 
     "argv": [
      "python3", 
      "-c", "from IPython.kernel.zmq.kernelapp import main; main()", 
      "-f", "{connection_file}"
     ], 
     "codemirror_mode": {
      "version": 2, 
      "name": "ipython"
     }
    }
    
  • 0

    如果你使用anaconda发行版,这对我有用(在macintosh上):

    $ conda create -n py3k python=3 anaconda
    
    $ source activate py3k
    
    $ ipython kernelspec install-self
    

    只是最后一个命令的注释:

    (py3k)Monas-MacBook-Pro:cs799 mona$ ipython kernelspec install-self
    [TerminalIPythonApp] WARNING | Subcommand `ipython kernelspec` is deprecated and will be removed in future versions.
    [TerminalIPythonApp] WARNING | You likely want to use `jupyter kernelspec` in the future
    [InstallNativeKernelSpec] WARNING | `jupyter kernelspec install-self` is DEPRECATED as of 4.0. You probably want `ipython kernel install` to install the IPython kernelspec.
    [InstallNativeKernelSpec] Installed kernelspec python3 in /usr/local/share/jupyter/kernels/python3
    (py3k)Monas-MacBook-Pro:cs799 mona$ ipython kernel install 
    Installed kernelspec python3 in /usr/local/share/jupyter/kernels/python3
    

    通过以上步骤在OSX Yosemite中测试并输入 jupter notebook 并在浏览器中创建新笔记本,您将看到以下屏幕截图:
    enter image description here

  • 2

    当您使用conda管理您的python环境时,请按照以下两个步骤操作:

    • activate py3 (在Windows上或Linux上的 source activate py3

    • conda install notebook ipykernel 或只是使用 conda install jupyter

  • 184

    该解决方案在官方文档中有详细记载:https://ipython.readthedocs.org/en/latest/install/kernel_install.html

    我尝试了第一种方法 . 由于我已经安装了 ipykernel ,只需运行 python3 -m ipykernel install --user 即可解决问题 .

相关问题