将 Conda 环境与 Jupyter Notebook 链接 [英] Link Conda environment with Jupyter Notebook
问题描述
我正在尝试为使用 python 做一些科学工作设置一个良好的环境.为此,我安装了 Jupyter &迷你康达.
I'm trying to set a good environnement for doing some scientific stuff with python. To do so, I installed Jupyter & miniconda.
然后我希望能够拥有不同的环境并将它们与 Jupyter 笔记本一起使用.所以我用 conda 创建了两个自定义环境: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
- 如何将
sys.executable
设置为 python2 的 miniconda env? - 如何将 conda env 与笔记本内核绑定?
source activate py35
是否与jupyter notebook
有链接?- 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 ?
我从 /usr/local/share/jupyter/kernels/python2
修改了 kernel.json
:
{
"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 包.
For Anaconda I suggest you a much easier and proper solution; just give a look at the nb_conda_kernels package.
它允许您在 Jupyter Notebook 中管理基于 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屋!