跑模型适合可能面临TF+Python的多个版本,所以需要随时切换环境,可以使用ipykernel,使用步骤如下:
1.初始化环境
pip install ipython prompt_toolkit
2.指定需要在notebook上进行切换的虚拟环境
python -m ipykernel install --user --name base --display-name base
这一步可能会出错报:from prompt_toolkit.eventloop import generator_to_async_generator, AsyncGeneratorItem
ImportError: cannot import name 'generator_to_async_generator'
![](https://img.haomeiwen.com/i4905257/e223781b560e8d9f.png)
3.出现以上问题主要是因为 prompt_toolkit版本和现在环境相冲突需要卸载进行重新安装,而且是需要卸载两次才能卸载干净,因为我环境有py2,py3两个版本都存在
pip uninstall -y ipython prompt_toolkit
![](https://img.haomeiwen.com/i4905257/1f07aefa31eeef18.png)
4.再重新安装时显示重新下载安装包
pip install ipython prompt_toolkit
![](https://img.haomeiwen.com/i4905257/b885f1e69c7133b6.png)
5.重新设置需要在notebook进行切换的环境
python -m ipykernel install --user --name base --display-name base
![](https://img.haomeiwen.com/i4905257/4d3ec3b90b9526f6.png)
6,页面成功显示可以进行切换
![](https://img.haomeiwen.com/i4905257/f5d6af84124cb15e.png)
7.列举虚拟环境内核
jupyter kernelspec list
![](https://img.haomeiwen.com/i4905257/d60e9b44bf50a53d.png)
8.删除已经内核环境
jupyter kernelspec remove python2
![](https://img.haomeiwen.com/i4905257/1075efa07c7eefa1.png)
网友评论