首页 > 解决方案 > Jupyter kernel points to the wrong Python

问题描述

I create a conda environment, activate install ipykernel, add it to jupyter kernelspec. This far, all works fine.

conda create -n MYENV python
conda activate MYENV
conda install ipykernel
python -m ipykernel install --user --name MYENV
conda deactivate
jupyter kernelspec list

MYENV /home/kara/.local/share/jupyter/kernels/MYENV

Then I launch the jupyter notebook on my base environment, and select the added kernel. However, while this kernel still runs, it uses the python from the base environment. When I type !which python in the notebook, it returns "/home/kara/anaconda3/bin/python" while my python in that environment is actually in;

conda activate MYENV
which python

/home/kara/anaconda3/envs/MYENV/bin/python

How can I get jupyter to find the correct python? Now, when I install a package in that environment, jupyter cannot find it. I suspect it's because the package install to a different environment.

标签: pythonvirtualenvjupyterconda

解决方案


推荐阅读