anaconda3+python3.8+tensorflow2.2配置
- 在“Anaconda Prompt”中输入,用Anaconda3创建一个环境名称为tensorflow虚拟环境
conda create -n tensorflow python=3.8
- “activate tensorflow” 激活该虚拟环境
activate tensorflow
当不使用tensorflow时,关闭tensorflow环境,命令为:deactivate
- 下载CPU版本的tensorflow
pip install tensorflow-cpu==2.2
- 检测是否安装成功,先进入python环境
import tensorflow as tf
tf.__version__
- 配置环境
conda install spyder=4.1.4
这里我之前没有加Spyder版本,安装完tensorflow中的Spyder后,无法打开,报错ModuleNotFoundError: No module named 'textdistance‘
检查后发现tensorflow环境和base环境中安装的Spyder版本不一致,把tensorflow中安装的Spyder版本设为何base环境一致的,成功打开ensorflow中的Spyder。
- 打开tensorflow中的Spyder后,运行之前的代码可能会报错
This command failed to be executed because an error occurred while trying to get the file code from Spyder's editor. The error was:
An exception has occurred, use %tb to see the full traceback.
TypeError: handle_get_file_code() got an unexpected keyword argument 'save_all'
此问题由更新spyder后内核版本冲突导致,在tensorflow环境中输入
(tensorflow) C:\Users\xxx>conda install spyder-kernels=1.9.3
即可。