(保姆教程)Spyder 配置Tensorflow(2.5.0)和keras(2.4.3)
前言
其实安装Tensorflow和keras的过程不难,但是寻找匹配的版本,以及使得Spyder适应花了自己很长时间!
安装Tensorflow
打开anaconda prompt
首先查看自己的python版本
python --version
接着创建一个新的环境
conda create -n tf python=3.9.7
进入这个环境
conda activate tf
安装Tensorflow
pip install tensorflow==2.5.0
安装Keras
首先输入以下两行代码()
conda install mingw libpython
pip install theano
安装对应的Keras(版本一定要对应)
pip install keras==2.4.3
适应Spyder
在安装完成之后打开Spyder会发现其实用的解释器还是base,这个时候我们需要切换到tf中的python.exe解释器,但是切换之后重启内核,会显示内核错误!
解决:
这个时候需要我们先在刚才的命令行中输入
conda install spyder
重新安装spyder,再次打开会发现可以正常运行
输入以下代码测试
import keras
from keras.datasets import mnist
(train_images,train_labels),(test_images,test_labels) = mnist.load_data() #加载数据
print('shape of train images is ',train_images.shape)
print('shape of train labels is ',train_labels.shape)
print('train labels is ',train_labels)
print('shape of test images is ',test_images.shape)
print('shape of test labels is',test_labels.shape)
print('test labels is',test_labels)
成功运行!