一、先创造自己所需的conda环境
二、进入conda环境内,添加当前环境到jupyter内核
# 进入虚拟环境
activate tensorflow
# 安装jupyter 和 notebook
pip install jupyter notebook
#安装ipykernel,并进行相关操作
pip install --user ipykernel
#若想多个环境集成,--user必填。有这个选项后配置文件皆写入到当前用户目录下,不受环境切换影响
python -m ipykernel install --user --name= "想展示的名字"
# 查看jupyter是否已添加虚拟环境
jupyter kernelspec list
三、切换想配置进内核的环境,重复以下操作
# 退出上一个添加过的虚拟环境
conda deactivate
#进入想添加的环境
conda activate pytorch
# 安装jupyter 和 notebook(这一步可能能省掉,没有测试,不确定)
pip install jupyter notebook
#安装ipykernel,并进行相关操作
pip install --user ipykernel
#若想多个环境集成,--user必填。有这个选项后配置文件皆写入到当前用户目录下,不受环境切换影响
python -m ipykernel install --user --name= "想展示的名字"
# 查看jupyter是否已添加虚拟环境
jupyter kernelspec list
配置后的状态
(base) ubuntu@VM-4-4-ubuntu:~$ ls /home/ubuntu/.local/share/jupyter/kernels/
python3 tensorflow test_env
(base) ubuntu@VM-4-4-ubuntu:~$ jupyter kernelspec list
Available kernels:
python3 /home/ubuntu/.local/share/jupyter/kernels/python3
tensorflow /home/ubuntu/.local/share/jupyter/kernels/tensorflow
test_env /home/ubuntu/.local/share/jupyter/kernels/test_env
(base) ubuntu@VM-4-4-ubuntu:~$ cat /home/ubuntu/.local/share/jupyter/kernels/tensorflow/kernel.json
{
"argv": [
"/home/ubuntu/anaconda3/envs/tensorflow/bin/python",#这个路径即为conda虚拟环境所在的路径
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "tensorflow",
"language": "python",
"metadata": {
"debugger": true
}
}(base) ubuntu@VM-4-4-ubuntu:~$
服务器端启用:
#进入任意某个安装好jupyter notebook的环境中
jupyter notebook --no-browser --ip=0.0.0.0 --port=8888
配置好的内核: