Doris232 发表于 2022-6-23 17:31

Anaconda中搭建Tensorflow2.1.0环境+安装Keras过程

Anaconda中搭建Tensorflow2.1.0环境+安装Keras过程


打开Anaconda Navigator和Anaconda Prompt,在Anaconda Prompt中输入下列代码,之后在Anaconda Navigator中就会出现一个新的环境tensorflow,见图1.
conda create -n tensorflow #建立一个名为tensorflow的环境(环境名字可以随便取,之后要在这个环境里安装tensorflow2.1.0)
conda activate tensorflow#激活该环境图1:



安装并升级pip
conda install pip #安装pip
pip list#查看安装了哪些包及对应版本,执行这条指令时可能会报错,错误的意思是pip的版本太低,同时会给出升级pip的指令,只要复制下来对应的指令并运行即可,之后输入pip list可以验证是否升级完成如果提示要升级pip,一定要输入相应的指令升级
安装Tensorflow2.1.0环境
pip install tensorflow==2.1.0-i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com这里使用的是阿里云镜像,如果安装失败考虑换镜像
常用的镜像如下:
https://pypi.tuna.tsinghua.edu.cn/simple/
https://pypi.mirrors.ustc.edu.cn/simple/
http://pypi.hustunique.com/
http://pypi.sdutlinux.org/
http://pypi.douban.com/simple/
http://mirrors.aliyun.com/pypi/simple/
安装keras
pip install keras==2.3.1-i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com之所以要安装keras2.3.1是因为与TensorFlow2.1.0匹配的keras的版本是keras2.3.1
检查安装结果,程序运行结果如图2
pip list图2:



可以看到tensoeflow2.1.0和keras2.3.1都已经安装完成,图2只截取了部分,但已经可以看出安装了很多包,这是因为包与包之间有依赖关系,当安装某个包时,其所依赖的包也会被安装。
在jupyter notebook中使用tensorflow
在Anaconda Navigator的Home中将Application on切换到tensorflow环境,该环境里是没有安装jupyter notebook的,因此需要先安装jupyter notebook。点击install,安装完毕后点击launch即可在jupyter notebook中打开刚刚安装好的tensorflow环境


在jupyter notebook中输入如下代码也可查看tensorflow以及keras的版本,程序的正常运行也进一步说明tensorflow与keras安装成功,可以正常使用


页: [1]
查看完整版本: Anaconda中搭建Tensorflow2.1.0环境+安装Keras过程