本文翻译自:Conda environments not showing up in Jupyter Notebook

I installed Anaconda (with Python 2.7), and installed Tensorflow in an environment called tensorflow . 我安装了Anaconda(使用Python 2.7),并在名为tensorflow的环境中安装了tensorflow I can import Tensorflow successfully in that environment. 我可以在该环境中成功导入Tensorflow。

The problem is that Jupyter Notebook does not recognize the new environment I just created. 问题在于Jupyter Notebook无法识别我刚刚创建的新环境。 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. 无论我从GUI导航还是从内部的命令行启动Jupyter笔记本tensorflow ENV,只有一个名为菜单内核Python [Root] ,并且Tensorflow无法导入。 Of course, I clicked on that option multiple times, saved file, re-opened, but these did not help. 当然,我多次单击该选项,保存了文件,然后重新打开,但是这些无济于事。

Strangely, I can see the two environments when I open the Conda tab on the front page of Jupyter. 奇怪的是,当我打开Jupyter主页上的Conda选项卡时,可以看到两种环境。 But when I open the Files tab, and try to new a notebook, I still end up with only one kernel. 但是,当我打开Files选项卡,并尝试new笔记本,我还是结束了只有一个内核。

I looked at this question: Link Conda environment with Jupyter Notebook But there isn't such a directory as ~/Library/Jupyter/kernels on my computer! 我看着这个问题: 用Jupyter Notebook链接Conda环境但是我的计算机上没有~/Library/Jupyter/kernels这样的目录! This Jupyter directory only has one sub-directory called runtime . 这个Jupyter目录只有一个子目录,称为runtime

I am really confused. 我真的很困惑。 Are Conda environments supposed to become kernels automatically? Conda环境是否应该自动成为内核? (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.) (我按照https://ipython.readthedocs.io/en/stable/install/kernel_install.html手动设置了内核,但被告知未找到ipykernel 。)


#1楼

参考:https://stackoom.com/question/2gAsZ/Jupyter-Notebook中未显示Conda环境


#2楼

The annoying thing is that in your tensorflow environment, you can run jupyter notebook without installing jupyter in that environment . 令人讨厌的是,在您的张量tensorflow环境中,您可以运行jupyter notebook 而无需在该环境中安装jupyter Just run 赶紧跑

(tensorflow) $ conda install jupyter

and the tensorflow environment should now be visible in Jupyter Notebooks started in any of your conda environments as something like Python [conda env:tensorflow] . tensorflow环境现在应该是可见的Jupyter笔记本电脑在你的任何启动conda环境,因为类似Python [conda env:tensorflow]


#3楼

If your environments are not showing up, you probably do not have nb_conda_kernels installed in the environment where Jupyter is installed. 如果您的环境未显示,则可能是在安装nb_conda_kernels的环境中未安装nb_conda_kernels。 Anaconda's documentation states that Anaconda的文档指出

nb_conda_kernels should be installed in the environment from which you run Jupyter Notebook or JupyterLab. nb_conda_kernels应该安装在运行Jupyter Notebook或JupyterLab的环境中。 This might be your base conda environment, but it need not be. 这可能是您的基本conda环境,但不一定如此。 For instance, if the environment notebook_env contains the notebook package, then you would run 例如,如果环境notebook_env包含notebook软件包,则可以运行

 conda install -n notebook_env nb_conda_kernels 

Any other environments you wish to access in your notebooks must have an appropriate kernel package installed. 您希望在笔记本中访问的任何其他环境都必须安装适当的内核软件包。 For instance, to access a Python environment, it must have the ipykernel package; 例如,要访问Python环境,它必须具有ipykernel软件包。 eg 例如

 conda install -n python_env ipykernel 

To utilize an R environment, it must have the r-irkernel package; 要使用R环境,它必须具有r-irkernel软件包。 eg 例如

 conda install -n r_env r-irkernel 

For other languages, their corresponding kernels must be installed. 对于其他语言,必须安装其相应的内核 。

Note that at the time originally posting this, there was a possible cause from nb_conda not yet supporting Python 3.6 environments . 请注意,在最初发布此内容时,可能是由于nb_conda不支持Python 3.6环境引起的 。

If other solutions fail to get Jupyter to recognize other conda environments, you can always install and run jupyter from within a specific environment. 如果其他解决方案无法使Jupyter识别其他conda环境,则始终可以在特定环境中安装并运行jupyter You may not be able to see or switch to other environments from within Jupyter though. 但是,您可能无法从Jupyter内部查看或切换到其他环境。

$ conda create -n py36_test -y python=3.6 jupyter
$ source activate py36_test
(py36_test) $ which jupyter
/home/schowell/anaconda3/envs/py36_test/bin/jupyter
(py36_test) $ jupyter notebook

Notice that I am running Python 3.6.1 in this notebook: 请注意,我正在此笔记本中运行Python 3.6.1:

Note that if you do this with many environments, the added storage space from installing Jupyter into every environment may be undesirable (depending on your system). 请注意,如果您在许多环境中执行此操作,则可能不希望将Jupyter安装到每个环境中而增加存储空间(取决于您的系统)。


#4楼

Just run conda install ipykernel in your new environment, only then you will get a kernel with this env. 只要在您的新环境中运行conda install ipykernel ,就可以使用此env获得内核。 This works even if you have different versions installed in each envs and it doesn't install jupyter notebook again. 即使您在每个环境中安装了不同的版本,也不会再次安装jupyter Notebook,此方法仍然有效。 You can start youe notebook from any env you will be able to see newly added kernels. 您可以从任何环境中启动笔记本,您将能够看到新添加的内核。


#5楼

I ran into this same problem where my new conda environment, myenv , couldn't be selected as a kernel or a new notebook. 我遇到了同样的问题,我的新conda环境myenv无法选择为内核或新笔记本。 And running jupter notebook from within the env gave the same result. 从环境中运行jupter notebook可以得到相同的结果。

My solution, and what I learned about how Jupyter notebooks recognizes conda-envs and kernels: 我的解决方案以及有关Jupyter笔记本如何识别conda-envs和内核的知识:

Installing jupyter and ipython to myenv with conda: 使用conda将jupyter和ipython安装到myenv

conda install -n myenv ipython jupyter

After that, running jupter notebook outside any env listed myenv as a kernel along with my previous environments. 之后,在任何环境之外运行jupter notebookmyenv与以前的环境一起列为内核。

Python [conda env:old]
Python [conda env:myenv]

Running the notebook once I activated the environment: 激活环境后运行笔记本:

source activate myenv
jupyter notebook

hides all my other environment-kernels and only shows my language kernels: 隐藏我所有其他环境内核,只显示我的语言内核:

python 2
python 3
R

#6楼

I don't think the other answers are working any more, as conda stopped automatically setting environments up as jupyter kernels. 我认为其他答案不再有效,因为conda停止自动将环境设置为jupyter内核。 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)"

As documented here: http://ipython.readthedocs.io/en/stable/install/kernel_install.html#kernels-for-different-environments Also see this issue . 如此处所述: http : //ipython.readthedocs.io/zh-CN/stable/install/kernel_install.html#kernels-for-different-environments也请参阅此问题 。

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 附录:您应该能够通过nb_conda_kernels conda install nb_conda_kernels安装nb_conda_kernels软件包,以自动添加所有环境,请参见https://github.com/Anaconda-Platform/nb_conda_kernels

Jupyter Notebook中未显示Conda环境相关推荐

  1. pandas使用set_table_attributes函数、display_html函数等在jupyter notebook中并排显示两个dataframe的内容(side by side)

    pandas使用set_table_attributes函数.display_html函数等在jupyter notebook中并排显示两个dataframe的内容(side by side) 目录

  2. cad中直径符号不显示_pyecharts图形在jupyter notebook中不显示的解决办法

    很多利用notebook做数据分析的小伙伴在安装pyecharts后容易忘记设置资源引用这一步骤,导致在使用 "图形对象.render_notebook()" 语句渲染到jupyt ...

  3. Jupyter notebook 使用多个Conda 环境

    conda install nb_conda_kernels 转载于:https://www.cnblogs.com/Neo007/p/9509333.html

  4. Jupyter notebook中怎么添加Pytorch运行环境

    打开Anaconda中的Anaconda Navigator,如下所示: 修改channel环境,如下红框所示: 找到Jupyter Notebook的位置,点击Install,图中因为已经安装,所以 ...

  5. jupyter notebook中创建环境、安装使用pytorch

    5.8 torch环境 Ref:https://zhuanlan.zhihu.com/p/101799677 添加镜像 conda config --add channels https://mirr ...

  6. Jupyter lab add kernel Python+Julia+R 【jupyter Notebook 切换Python环境】and【在jupyter Notebook中安装第三方库】

    新增虚拟环境 conda create -n py2 python=2.7 进入python2的环境 conda activate py2 安装python2的内核并应用 python2 -m pip ...

  7. WINDOWS在jupyter notebook中导入opencv显示报错:most likely due to a circular import

    问题:已有python,在经过下载anacoda后欲导入opencv报错 当时思路:先把电脑中含有有opencv的文件删除,重新安装opencv 然后在CSDN中查解决方案: 经过在anaconda中 ...

  8. python matplotlab在jupyter notebook中画图不显示怎么办?(%matplotlib inline)

    在程序中代码最上方加上: 总结:%matplotlib inline 可以在Ipython编译器里直接使用,功能是可以内嵌绘图,并且可以省略掉plt.show()这一步. 引用文章1: 解决jupyt ...

  9. python 数学公式显示_ipython jupyter notebook中显示图像和数学公式实例

    1. # 可以使用LaTeX表示数学公式 # 可以使用LaTeX表示数学公式 from IPython.display import Latex Latex(r"$\sqrt{x^2+y^2 ...

最新文章

  1. Linux中逻辑卷相关知识简介
  2. Noip前的大抱佛脚----字符串
  3. C#:导入Excel通用类(CSV格式)
  4. Golang 删除切片指定元素
  5. Delphi中的字符串压缩与解压缩
  6. php 网页解析错误,php-解析错误:语法错误,文件意外结束
  7. 逐帧动画 and 有限状态机(fsm)
  8. 毕设题目:Matlab图像重建
  9. jquery中使用ajax的php实例
  10. win7系统64位下安装sql server2000时提示兼容性问题
  11. 对本人所发资源“金山词霸2010牛津旗舰版安装及故障终极解决方案”的说明
  12. 802.1Q封装的VLAN数据帧格式
  13. Tair存储引擎简单介绍以及常见API操作
  14. layui模块显示收缩_修改layui的后台模板的左侧导航栏可以伸缩的方法
  15. Failed to remove network i5unxjx3ahdfrhksw0fmyqpjd: Error response from daemon: network *
  16. 苹果开发者平台-《测试证书》生成流程
  17. java 内存 pdf_jvm内存模型高清版.pdf
  18. 张一鸣卸任字节跳动 CEO,网友调侃因未完成去年 OKR 被优化!
  19. html5文档类型的doctype,DOCTYPE 文档类型
  20. 惠普战66一代拆机_惠普战66 Pro笔记本详细拆机教程

热门文章

  1. Mysql Sql语句令某字段值等于原值加上一个字符串
  2. CodeForces 274B Zero Tree :每次选包含1节点的一棵子树,将该子树所有值都+1或者-1最少多少步可以使树值全部为0 :树型dp...
  3. Modal View Controllers, Not Model-View-Controller(MVC)
  4. 温习php一(apache和php的配置)
  5. Cobalt Strike 3.13的新功能
  6. 官方版sublime Text3汉化和激活注册码
  7. iview“官方“实现的右键菜单
  8. 第九届全国大学生数学竞赛(江西赛区)数学类获奖学生名单
  9. 轮胎的体积与面积计算
  10. 机器学习基石笔记-Lecture 14 Regularization