如何将 conda 环境添加到 jupyter 实验室 [英] How to add conda environment to jupyter lab

查看:78
本文介绍了如何将 conda 环境添加到 jupyter 实验室的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Jupyter Lab,但在添加 conda 环境时遇到问题.这个想法是从我的基础环境启动 Jupyter Lab,然后能够选择我的其他 conda 环境作为内核.

I'm using Jupyter Lab and I'm having trouble to add conda environment. The idea is to launch Jupyter Lab from my base environment, and then to be able to choose my other conda envs as kernels.

我安装了 nb_conda_kernels 包,它应该可以做到这一点,但它没有按我想要的方式工作.确实,假设我创建了一个新的 Conda 环境,然后我从基础启动了 jupyter 实验室,我无法将新环境视为可用内核.

I installed the package nb_conda_kernels which is supposed to do just that, but it's not working as I want. Indeed, let's assume I create a new Conda Environment, then I launch jupyter lab from base, I can't see the new environment as an available kernel.

我找到了一个修复",它每次都有效,但一点也不方便.如果我在我的新环境中安装 Jupyter Notebook,然后从这个新环境启动一个 jupyter notebook,关闭它,回到基础环境,然后从基础环境启动 Jupyter Lab,我的新环境可以作为 Jupyter Lab 的内核使用.

I have found a "fix", which works everytime but is not convenient at all. If I install Jupyter Notebook in my new environment, then launch a jupyter notebook from this new environment, close it, go back to base environment, and then launch Jupyter Lab from base environment, my new environment is available as a kernel in Jupyter Lab.

如果您知道如何在没有此修复"的情况下使其工作,我将不胜感激.

If you know how to make it work without this "fix", I would be very grateful.

推荐答案

假设你的 conda-env 被命名为 cenv,它很简单:

Assuming your conda-env is named cenv, it is as simple as :

$ conda activate cenv           # . ./cenv/bin/activate in case of virtualenv
(cenv)$ conda install ipykernel
(cenv)$ ipython kernel install --user --name=<any_name_for_kernel>
(cenv)$ conda deactivate

如果您重新启动 jupyter notebook/lab,您将能够看到可用的新内核.对于较新版本的 jupyter 内核将在不重新启动实例的情况下出现.只需按 F5 刷新即可.

If you restart your jupyter notebook/lab you will be able to see the new kernel available. For newer versions of jupyter kernel will appear without restarting the instance. Just refresh by pressing F5.

PS:如果您使用的是 virtualenv 等,上述步骤适用.

PS: If you are using virtualenv etc. the above steps hold good.

这篇关于如何将 conda 环境添加到 jupyter 实验室的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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