将Conda环境与Jupyter Notebook联系起来 [英] Link Conda environment with Jupyter Notebook
问题描述
我正在努力为python做一些科学的东西设置一个良好的环境。为此,我安装了Jupyter& miniconda。
I'm trying to set a good environnement for doing some scientific stuff with python. To do so, I installed Jupyter & miniconda.
然后我希望能够拥有不同的环境,并将它们与Jupyter笔记本一起使用。所以我用conda创建了两个自定义env:py27和py35。
Then I want to be able to have different environnement and use them with Jupyter notebooks. So I created two custom envs with conda : py27 and py35.
> conda env list
# conda environments:
#
py27 /Users/***/miniconda3/envs/py27
py35 /Users/***/miniconda3/envs/py35
root * /Users/***/miniconda3
然后在我的笔记本上我有两个内核 python 2
和 python 3
。
在笔记本中,我使用python3内核获得以下内容:
Then on my notebook I have two kernels python 2
and python 3
.
Inside a notebook, I get the following with the python3 kernel :
> import sys
> print(sys.executable)
/Users/***/miniconda3/envs/py35/bin/python
这与python2内核:
And this with the python2 kernel :
> import sys
> print(sys.executable)
/usr/local/opt/python/bin/python2.7
- 如何为python2设置
sys.executable
到miniconda env? - 怎么能我用一个笔记本内核绑定一个conda env?
- 正在做
source activate py35
有一个链接jupyter笔记本
? - How can I set the
sys.executable
to miniconda env for python2 ? - How can I bind a conda env with a notebook kernel ?
- Is doing
source activate py35
has a link withjupyter notebook
?
我想我真的错过了什么。
I think I really missed something.
谢谢大家。
---编辑
我有多个jupyter bin:
I have multiple jupyter bin :
> where jupyter
/usr/local/bin/jupyter
/usr/local/bin/jupyter
/Users/ThomasDehaeze/miniconda3/bin/jupyter
我这里只有一个内核 / usr / local / share / jupyter / kernels / python2
。
但是在Jupyter里面,我有两个内核, python2
和 python3
。我在哪里可以找到另一个?
I have only one kernel here /usr/local/share/jupyter/kernels/python2
.
But inside Jupyter, I have two kernels, python2
and python3
. Where can I find the other one ?
我修改了 kernel.json
来自 / usr / local / share / jupyter / kernels / python2
:
{
"display_name": "Python 2",
"language": "python",
"argv": [
"/Users/***/miniconda3/envs/py27/bin/python2.7",
"-m",
"ipykernel",
"-f",
"{connection_file}"
]
}
然后:
import sys
print(sys.executable)
/usr/local/opt/python/bin/python2.7
所以没有任何改变
推荐答案
<对于Anaconda,我建议你一个更容易和更合适的解决方案;
只需查看 nb_conda_kernels包。
它允许你在Jupyter笔记本中管理你的conda基于环境的内核。
It allows you to "manage your conda environment-based kernels inside the Jupyter Notebook".
自Anaconda版本4.1.0以来应该包含它,否则只需使用
Is should be included since Anaconda version 4.1.0, otherwise simply use
conda install nb_conda
现在你应该可以从Notebook界面管理所有直接。
Now you should be able to manage all direcly from the Notebook interface.
这篇关于将Conda环境与Jupyter Notebook联系起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!