jupyter内核配置 anaconda虚拟环境

打开Anaconda Prompt

1)激活虚拟环境(后续步骤都在该环境下完成)

2)在该虚拟环境下安装ipykernel库,利用ipykernel库将该虚拟环境写入到jupyter中

conda install ipykernel

3)将该环境写入jupyter(一个环境就是一个内核)

注意:name后跟当前环境名;display-name后跟在jupyter中内核的显示名称(内核名最好和环境名一样,统一管理)

python -m ipykernel install --user --name torch1.5.1 --display-name torch1.5.1

jupyter内核配置 anaconda虚拟环境_第1张图片

 jupyter常用的内核命令:

# 查看所有内核
jupyter kernelspec list

jupyter内核配置 anaconda虚拟环境_第2张图片

# 删除 jupyter 内核
jupyter kernelspec remove kernelname(内核名称)

问题描述:

在cmd终端、pycharm中import torch成功,但在jupyter中报错:ModuleNotFoundError: No module named 'torch'

解决方案:

首先激活虚拟环境,然后进行如下操作:

1.安装 jupyter notebook 一系列依赖库

conda install jupyter

2.安装nb_conda_kernels

conda install nb_conda_kernels

重新打开jupyter,import torch 可以正常使用了!!!

你可能感兴趣的:(jupyter,python,linux)