安装tensorflow环境的时候,一定要先弄清楚对应的版本对应的情况,不要上来就pip install tensorflow,pip install keras,最后发现全是坑。

一、Tensorflow、Keras和python版本对照

二者对应版本号如表所示(Keras新版本对Tensorflow老版本不兼容,需注意安装版本号)


 

二、Tensorflow和Keras安装流程

这里安装python=3.6,Tensorflow=2.0,Keras=2.3.1

1. anaconda安装python环境

1)在Anaconda Prompt中输入命令,创建conda环境

conda create -n tensorflow python=3.6

2)激活环境 

activate tensorflow

2. 安装Tensorflow

pip install tensorflow==2.0.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

3. 安装Keras 

pip install keras==2.3.1 -i https://pypi.tuna.tsinghua.edu.cn/simple

结果查看(切换到python环境): 

在这里插入图片描述

注意:

如果开始你安装的时候没有注意版本问题,直接使用pip install tensorflow安装,安装过程中不会出现问题,在import会报错:

W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory
I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.

这就是版本不匹配的问题,你需要安装对应版本的tensorflow。

转自:Tensorflow和Keras版本对照及环境安装_小朱小朱绝不服输的博客-CSDN博客_keras和tensorflow的版本对应

更多信息可参考:

keras和tensorflow的版本对应关系_DLANDML的博客-CSDN博客_tensorflow与keras版本关系

版本问题---keras和tensorflow的版本对应关系 - WP的烂笔头 - 博客园

 

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐