如何使 conda 虚拟环境持久化并可用于 Jupyter Notebook 等工具? [英] How to make conda virtual environments persistent and available for tools such as Jupyter Notebook?

查看:52
本文介绍了如何使 conda 虚拟环境持久化并可用于 Jupyter Notebook 等工具?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当在 shell 窗口中激活 conda 环境时,该环境仅在该窗口中处于活动状态(即非持久性).因此,当我导航到另一个窗口中的项目位置时,root"虚拟环境处于活动状态.

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)笔记本内核:

假设您已经使用 conda create -n jupyter-env35 python=3.5 创建了一个名为 jupyter-env35 的 conda 环境,现在想在 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.

如果你想从notebook界面删除内核,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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆