我无法让我的 anaconda 环境出现在 jupyter 笔记本中。我不确定当前的解决方案是否过时或者我做错了什么。我使行为清晰,希望能够更容易地识别问题。
我从他们的网站为 Linux 安装 Anaconda3-2021.11 :
$ sh ./Downloads/Anaconda3-2021.11-Linux-x86_64.sh
$ reboot
$ conda update conda -y
$ conda install nb_conda_kernels -y
我们看到以下 conda 环境:
$ conda env list
# conda environments:
#
base * /home/user/anaconda3
我们可以看到在哪里python
:
$ echo $CONDA_DEFAULT_ENV
base
$ which python
/home/user/anaconda3/bin/python
$ python --version
Python 3.9.7
我使用 jupyter 和 nb_conda_kernels 观察到以下内容:
$ jupyter kernelspec list
[ListKernelSpecs] WARNING | Config option `kernel_spec_manager_class` not recognized by `ListKernelSpecs`.
Available kernels:
python3 /home/user/anaconda3/share/jupyter/kernels/python3
$ python -m nb_conda_kernels list
[ListKernelSpecs] WARNING | Config option `kernel_spec_manager_class` not recognized by `ListKernelSpecs`.
[ListKernelSpecs] [nb_conda_kernels] enabled, 1 kernels found
Available kernels:
python3 /home/user/anaconda3/share/jupyter/kernels/python3
conda-root-py /home/user/anaconda3/share/jupyter/kernels/python3
如果我尝试创建这样的环境:
conda create -n test_env python=3.8
它将显示在 conda 中:
$ conda env list
# conda environments:
#
base * /home/user/anaconda3
test_env /home/user/anaconda3/envs/test_env
我们可以看到 test_env 的 python 在哪里:
$ conda activate test_env
$ echo $CONDA_DEFAULT_ENV
test_env
$ which python
/home/user/anaconda3/envs/test_env/bin/python
$ python --version
Python 3.8.13
但是,当在和中时base
,输出不会改变。jupyter kernelspec list
python -m nb_conda_kernels list
如果我尝试手动进行:
$ python -m ipykernel install --user --name test_env --display-name "Python (test_env)"
Installed kernelspec test_env in /home/user/.local/share/jupyter/kernels/test_env
它可能会出现在 jupyter kernelspec 和 nb_conda_kernels 中:
$ jupyter kernelspec list
[ListKernelSpecs] WARNING | Config option `kernel_spec_manager_class` not recognized by `ListKernelSpecs`.
Available kernels:
test_env /home/user/.local/share/jupyter/kernels/test_env
python3 /home/user/anaconda3/share/jupyter/kernels/python3
$ python -m nb_conda_kernels list
[ListKernelSpecs] WARNING | Config option `kernel_spec_manager_class` not recognized by `ListKernelSpecs`.
[ListKernelSpecs] [nb_conda_kernels] enabled, 1 kernels found
Available kernels:
test_env /home/deepology/.local/share/jupyter/kernels/test_env
python3 /home/user/anaconda3/share/jupyter/kernels/python3
conda-root-py /home/user/anaconda3/share/jupyter/kernels/python3
但是如果你真的启动jupyter notebook
并创建了一个test_env
笔记本,那么我们观察到
笔记本脚本输入
import sys
print(sys.executable)
笔记本脚本输出
/home/user/anaconda3/bin/python
3.9.7 (default, Sep 16 2021, 13:09:58)
[GCC 7.5.0]
如果我重新启动没有任何变化。
我究竟做错了什么?
您需要在激活的test_env
.
python -m ipykernel install --user --name test_env --display-name "Python (test_env)"
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句