跑模型适合可能面临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'

3.出现以上问题主要是因为 prompt_toolkit版本和现在环境相冲突需要卸载进行重新安装,而且是需要卸载两次才能卸载干净,因为我环境有py2,py3两个版本都存在
pip uninstall -y ipython prompt_toolkit

4.再重新安装时显示重新下载安装包
pip install ipython prompt_toolkit

5.重新设置需要在notebook进行切换的环境
python -m ipykernel install --user --name base --display-name base

6,页面成功显示可以进行切换

7.列举虚拟环境内核
jupyter kernelspec list

8.删除已经内核环境
jupyter kernelspec remove python2

网友评论