(保姆教程)Spyder 配置Tensorflow(2.5.0)和keras(2.4.3)

(保姆教程)Spyder 配置Tensorflow(2.5.0)和keras(2.4.3)

前言

其实安装Tensorflow和keras的过程不难,但是寻找匹配的版本,以及使得Spyder适应花了自己很长时间!

安装Tensorflow

打开anaconda prompt

image-20220518000705721

首先查看自己的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解释器,但是切换之后重启内核,会显示内核错误!

image-20220518000619254

解决:

这个时候需要我们先在刚才的命令行中输入

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)

image-20220518000514053

成功运行!

但美中不足的是,使用tensorflow之后之前conda自带的很多库就用不了了,需要重新pip或者conda

  • 11
    点赞
  • 69
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值