如何让conda虚拟环境持续存在并可用于Jupyter Notebook等工具? [英] How to make conda virtual environments persistent and available for tools such as Jupyter Notebook?
问题描述
当在shell窗口中激活conda环境时,环境仅在该窗口中处于活动状态(即不是持久的)。因此,当我导航到另一个窗口中的项目位置时,根虚拟环境处于活动状态。
When a conda environment is activated in a shell window, the environment is only active in that window (i.e. not persistent). So when I navigate to the project location in another window, the "root" virtual environment is active.
我是否遗漏了某些内容或这是预期的行为?
Am I missing something or is this the intended behaviour?
如何让Jupyter Notebook等工具访问创建的环境?
How to give tools such as Jupyter Notebook access to the created environment?
推荐答案
注册一个(python)笔记本内核:
假设你创建了一个名为 jupyter-env35
的conda环境 conda create -n jupyter-env35 python = 3.5
现在想在jupyter中使用它。
Register a (python) notebook kernel:
Let's suppose you have created a conda environment named jupyter-env35
with conda create -n jupyter-env35 python=3.5
and now want to use it in jupyter.
安装和注册环境中的python内核将通过图形笔记本界面提供。
Installing and registering a python kernel in the environment will make it available over the graphical notebook interface.
为此,首先安装ipython内核:
To do so, first install the ipython kernel:
conda install -n jupyter-env35 ipykernel
然后激活环境并注册内核:
Then activate the environment and register the kernel:
source activate jupyter-env35
ipython kernel install --user --name jupyter-env35
当你现在启动juypter时,它会显示 jupyter-env35
作为可用内核列表中的内核。如果你选择它,安装在 juypter-env35
中的所有软件包都将可用。
When you now fire up juypter, it will show jupyter-env35
as a kernel in the list of available kernels. If you select it, all packages installed into juypter-env35
will be available.
如果你想从笔记本界面删除内核, jupyter --data-dir
,将打印出jupyter的数据目录。
If you want delete the kernel from the notebook interface, jupyter --data-dir
, will print out jupyter's data directory.
导航到打印文件夹,找到子文件夹 kernels
并删除包含内核名称的文件夹(这里 jupyter-env35
)。之后,内核将不再出现在jupyter中。
Navigate to the printed folder, find the subfolder kernels
and delete the folder with the name of your kernel (here jupyter-env35
). After that the kernel will not show up in jupyter anymore.
这篇关于如何让conda虚拟环境持续存在并可用于Jupyter Notebook等工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!