本文介绍了Conda 环境未出现在 Jupyter Notebook 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了 Anaconda(使用 Python 2.7),并在名为 tensorflow 的环境中安装了 Tensorflow.我可以在那个环境中成功导入 Tensorflow.

I installed Anaconda (with Python 2.7), and installed Tensorflow in an environment called tensorflow. I can import Tensorflow successfully in that environment.

问题是 Jupyter Notebook 无法识别我刚刚创建的新环境.无论我是从 GUI 导航器还是从命令行tensorflow env 中启动 Jupyter Notebook,菜单中都只有一个名为 Python [Root] 的内核,并且无法导入 Tensorflow.当然,我多次点击该选项,保存文件,重新打开,但这些都没有帮助.

The problem is that Jupyter Notebook does not recognize the new environment I just created. No matter I start Jupyter Notebook from the GUI Navigator or from the command line within the tensorflow env, there is only one kernel in the menu called Python [Root], and Tensorflow cannot be imported. Of course, I clicked on that option multiple times, saved file, re-opened, but these did not help.

奇怪的是,打开 Jupyter 的首页的 Conda 选项卡时,可以看到两个环境.但是当我打开 Files 标签并尝试 new 一个 notebook 时,我仍然只有一个内核.

Strangely, I can see the two environments when I open the Conda tab on the front page of Jupyter. But when I open the Files tab, and try to new a notebook, I still end up with only one kernel.

我看了这个问题:将 Conda 环境与 Jupyter Notebook 链接但是我的电脑上没有~/Library/Jupyter/kernels这样的目录!这个 Jupyter 目录只有一个名为 runtime 的子目录.

I looked at this question:Link Conda environment with Jupyter NotebookBut there isn't such a directory as ~/Library/Jupyter/kernels on my computer! This Jupyter directory only has one sub-directory called runtime.

我真的很困惑.Conda 环境是否应该自动成为内核?(我跟着 https://ipython.readthedocs.io/en/stable/install/kernel_install.html 手动设置内核,但被告知找不到 ipykernel.)

I am really confused. Are Conda environments supposed to become kernels automatically? (I followed https://ipython.readthedocs.io/en/stable/install/kernel_install.html to manually set up the kernels, but was told that ipykernel was not found.)

推荐答案

我认为其他答案不再有效,因为 conda 停止自动将环境设置为 jupyter 内核.您需要通过以下方式为每个环境手动添加内核:

I don't think the other answers are working any more, as conda stopped automatically setting environments up as jupyter kernels. You need to manually add kernels for each environment in the following way:

source activate myenv
python -m ipykernel install --user --name myenv --display-name "Python (myenv)"

如此处所述:http://ipython.readthedocs.io/en/stable/install/kernel_install.html#kernels-for-different-environments另请参阅此问题.

As documented here:http://ipython.readthedocs.io/en/stable/install/kernel_install.html#kernels-for-different-environmentsAlso see this issue.

附录:您应该能够使用 conda install nb_conda_kernels 安装 nb_conda_kernels 包以自动添加所有环境,请参阅 https://github.com/Anaconda-Platform/nb_conda_kernels

Addendum:You should be able to install the nb_conda_kernels package with conda install nb_conda_kernels to add all environments automatically, see https://github.com/Anaconda-Platform/nb_conda_kernels

这篇关于Conda 环境未出现在 Jupyter Notebook 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-03 22:34