首页 > 解决方案 > 无法在 jupyter 笔记本中注册/访问/使用 conda 虚拟环境

问题描述

SO上有很多与此相关的问题,但是所有答案似乎都不适合我。

问题:

我有一个名为rideaux 的conda 环境。我希望从我的 jupyter 笔记本中访问这个环境。但是,在 jupyter 笔记本中,唯一可用的内核是默认内核。

在此处输入图像描述

为了测试,我尝试导入 conda 环境中可用的包,但正如预期的那样,这在可用内核中不起作用。

我尝试了什么:

根据相关问题答案(此处未列出更多)。

  1. 首先,我尝试在rideaux 环境中简单地运行jupyter notebook 服务器。这与上图没有任何变化,即rideaux 内核不可用。

  2. 接下来,我尝试使用该nb_conda_kernels软件包。我安装conda install -n notebook_env nb_conda_kernels在我的基础环境和我的rideaux 环境中。我也安装ipykernel在我的rideaux 环境中conda install ipykernel。然后,从rideaux 环境启动一个笔记本服务器,结果与上图没有任何变化。

  3. 我试图通过ipython kernel install --user --name=rideaux在rideaux 环境中运行来注册conda 环境。这导致没有任何变化。

一般信息和故障排除。

which jupyter在rideaux 环境中运行会从环境内部返回一个可执行文件。

运行jupyter kernelspec list返回以下内容。这python3似乎是上图中看到的那个。那为什么rideaux内核没有出现呢?

Available kernels:
  rideaux    /home/mjpvanzuijlen/.local/share/jupyter/kernels/rideaux
  python3    /home/mjpvanzuijlen/anaconda3/envs/rideaux/share/jupyter/kernels/python3

在笔记本中运行!jupyter-troubleshoot会返回以下输出。它没有提到rideaux环境,返回的环境which jupyter也在这里不可见。这可能意味着正在运行错误的 jupyter?我不知道。

$PATH:
    /snap/jupyter/6/bin
    /snap/jupyter/6/usr/sbin
    /snap/jupyter/6/usr/bin
    /snap/jupyter/6/sbin
    /snap/jupyter/6/bin
    /home/mjpvanzuijlen/snap/jupyter/common/bin
    /usr/local/sbin
    /usr/local/bin
    /usr/sbin
    /usr/bin
    /sbin
    /bin
    /usr/games
    /usr/local/games

sys.path:
    /snap/jupyter/6/bin
    /snap/jupyter/6/lib/python37.zip
    /snap/jupyter/6/lib/python3.7
    /snap/jupyter/6/lib/python3.7/lib-dynload
    /snap/jupyter/6/lib/python3.7/site-packages

sys.executable:
    /snap/jupyter/6/bin/python3.7

sys.version:
    3.7.3 | packaged by conda-forge | (default, Mar 27 2019, 23:01:00) 
    [GCC 7.3.0]

platform.platform():
    Linux-4.15.0-140-generic-x86_64-with-glibc2.10

which -a jupyter:
    /snap/jupyter/6/bin/jupyter
    /snap/jupyter/6/bin/jupyter

标签: pythonjupyter-notebookanacondajupyterconda

解决方案


推荐阅读