欢迎光临散文网 会员登陆 & 注册

在jupyter notebook中添加虚拟环境

2023-07-18 17:19 作者:源源常新  | 我要投稿

查看当前已创建的虚拟环境

使用jupyter notebook时可能会发现里面没有已经创建的虚拟环境,可以在命令行中输入:conda env list查看已经创建的虚拟环境(如图1)。图中的*表示当前激活的是名为d2l的虚拟环境,默认情况*在base那一行。

图1 已创建的虚拟环境列表

查看jupyter notebook中能使用的虚拟环境

打开jupyter notebook后点击new,可以看到能在jupyter notebook中使用的虚拟环境。(图2)

图2 查看jupyter notebook中能使用的虚拟环境

在jupyter notebook添加已创建的虚拟环境

接下来介绍将我创建的一个虚拟环境tensorflow添加到jupyter notebook

在命令行中输入命令:python -m ipykernel install --name tensorflow(图3)这里的tensorflow是我创建的虚拟环境名,如果想要添加其他的虚拟环境到jupyter notebook中,将这里的tensorflow换成其他虚拟环境的名字即可。

图3 添加虚拟环境tensorflow到jupyter notebook

在jupyter notebook中切换虚拟环境

再次打开jupyter notebook,在kernel栏选择Change kernel就可以看到tensorflow添加到虚拟环境了(图4),点击pytorch在jupyter notebook中就会使用pytorch虚拟环境,点击d2l在jupyter notebook中就会使用d2l虚拟环境,需要切换不同的虚拟环境只需要点击不同的环境名即可。

图4 在jupyter notebook中切换虚拟环境


在jupyter notebook中添加虚拟环境的评论 (共 条)

分享到微博请遵守国家法律