更换jupyter notebook的kernel的python环境

更改jupyter notebook的python环境变量
当我们在使用jupyter notebook的时候常常会出现导入的包不存在的情况

import torch

报错

ModuleNotFoundError: No module named 'torch'

原因可能是kernel的环境变量是默认的,不是自己安装的python虚拟环境的,这时候需要更换python环境。
首先在命令行输入jupyter kernelspec list查看jupyter kernels

 python3    d:\anaconda\envs\pytorch\share\jupyter\kernels\python3

进入到当前目录下,打开kernel.json文件

{
 "argv": [
  "D:\\anaconda\\envs\\pytorch\\python.exe",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ],
 "display_name": "python3",
 "language": "python"
}

其中第三行就是kernel的python环境,只需要将该路径更换成自己创建的虚拟环境的python路径即可。
修改完之后,重启jupyter notenook服务,就可以使用。

如果在jupyter notebook的服务器仍然报错为 no kernels,那么可能是因为自己创建的虚拟环境中,没有安装ipykernel
这时候需要在自己创建的虚拟环境中安装ipykernel

pip install ipykernel -i https://pypi.douban.com/simple

使用豆瓣源加速安装,安装完之后,重启jupyter notebook服务,就可正常运行。

参考:https://blog.csdn.net/castle_cc/article/details/86491524
https://www.jianshu.com/p/538c4aa17ba8

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值