Tensorflow和Keras版本对照及环境安装

在安装tensorflow环境的时候,一定要先弄清楚对应的版本对应的情况,不要上来就pip install tensorflowpip install keras。最后发现全是坑。下面就列一下,tensorflow和keras以及对应的python版本,然后再列一下我成功安装的流程。

一、Tensorflow、Keras和python版本对照

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

Framework Env name Description
TensorFlow 2.2 tensorflow-2.2 TensorFlow 2.2.0 + Keras 2.3.1 on Python 3.7.
TensorFlow 2.1 tensorflow-2.1 TensorFlow 2.1.0 + Keras 2.3.1 on Python 3.6.
TensorFlow 2.0 tensorflow-2.0 TensorFlow 2.0.0 + Keras 2.3.1 on Python 3.6.
TensorFlow 1.15 tensorflow-1.15 TensorFlow 1.15.0 + Keras 2.3.1 on Python 3.6.
TensorFlow 1.14 tensorflow-1.14 TensorFlow 1.14.0 + Keras 2.2.5 on Python 3.6.
TensorFlow 1.13 tensorflow-1.13 TensorFlow 1.13.0 + Keras 2.2.4 on Python 3.6.
TensorFlow 1.12 tensorflow-1.12 TensorFlow 1.12.0 + Keras 2.2.4 on Python 3.6.
tensorflow-1.12:py2 TensorFlow 1.12.0 + Keras 2.2.4 on Python 2.
TensorFlow 1.11 tensorflow-1.11 TensorFlow 1.11.0 + Keras 2.2.4 on Python 3.6.
tensorflow-1.11:py2 TensorFlow 1.11.0 + Keras 2.2.4 on Python 2.
TensorFlow 1.10 tensorflow-1.10 TensorFlow 1.10.0 + Keras 2.2.0 on Python 3.6.
tensorflow-1.10:py2 TensorFlow 1.10.0 + Keras 2.2.0 on Python 2.
TensorFlow 1.9 tensorflow-1.9 TensorFlow 1.9.0 + Keras 2.2.0 on Python 3.6.
tensorflow-1.9:py2 TensorFlow 1.9.0 + Keras 2.2.0 on Python 2.
TensorFlow 1.8 tensorflow-1.8 TensorFlow 1.8.0 + Keras 2.1.6 on Python 3.6.
tensorflow-1.8:py2 TensorFlow 1.8.0 + Keras 2.1.6 on Python 2.
TensorFlow 1.7 tensorflow-1.7 TensorFlow 1.7.0 + Keras 2.1.6 on Python 3.6.
tensorflow-1.7:py2 TensorFlow 1.7.0 + Keras 2.1.6 on Python 2.
TensorFlow 1.5 tensorflow-1.5 TensorFlow 1.5.0 + Keras 2.1.6 on Python 3.6.
tensorflow-1.5:py2 TensorFlow 1.5.0 + Keras 2.0.8 on Python 2.
TensorFlow 1.4 tensorflow-1.4 TensorFlow 1.4.0 + Keras 2.0.8 on Python 3.6.
tensorflow-1.4:py2 TensorFlow 1.4.0 + Keras 2.0.8 on Python 2.
TensorFlow 1.3 tensorflow-1.3 TensorFlow 1.3.0 + Keras 2.0.6 on Python 3.6.
tensorflow-1.3:py2 TensorFlow 1.3.0 + Keras 2.0.6 on Python 2.

安装的时候按照对应的版本进行安装。

二、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。

来源:小朱小朱绝不服输

物联沃分享整理
物联沃-IOTWORD物联网 » Tensorflow和Keras版本对照及环境安装

发表评论