關(guān)于Tensorflow和Keras版本對(duì)照及環(huán)境安裝
在安裝tensorflow環(huán)境的時(shí)候,一定要先弄清楚對(duì)應(yīng)的版本對(duì)應(yīng)的情況,不要上來就 pip install tensorflow , pip install keras 。
最后發(fā)現(xiàn)全是坑。
下面就列一下,tensorflow和keras以及對(duì)應(yīng)的python版本,然后再列一下我成功安裝的流程。
一、Tensorflow、Keras和python版本對(duì)照
二者對(duì)應(yīng)版本號(hào)如表所示(Keras新版本對(duì)Tensorflow老版本不兼容,需注意安裝版本號(hào))
| 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. |
安裝的時(shí)候按照對(duì)應(yīng)的版本進(jìn)行安裝。
二、Tensorflow和Keras安裝流程
這里安裝python=3.6,Tensorflow=2.0,Keras=2.3.1
1. anaconda安裝python環(huán)境
1)在Anaconda Prompt中輸入命令,創(chuàng)建conda環(huán)境
conda create -n tensorflow python=3.6
2)激活環(huán)境
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
結(jié)果查看(切換到python環(huán)境):

注意:
如果開始你安裝的時(shí)候沒有注意版本問題,直接使用 pip install tensorflow 安裝,安裝過程中不會(huì)出現(xiàn)問題
在import會(huì)報(bào)錯(cuò):
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.
這就是版本不匹配的問題,你需要安裝對(duì)應(yīng)版本的tensorflow。
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
使用Python打造一個(gè)專業(yè)的PDF文本提取工具
這篇文章主要為大家詳細(xì)介紹了如何使用Python開發(fā)一個(gè)專業(yè)的PDF文本提取工具,幫助大家從PDF文檔中高效提取結(jié)構(gòu)化文本數(shù)據(jù),適用于數(shù)據(jù)分析,內(nèi)容歸檔和知識(shí)管理等場(chǎng)景2025-07-07
python HTTPX庫實(shí)現(xiàn)同步異步請(qǐng)求用法示例
這篇文章主要為大家介紹了python HTTPX庫實(shí)現(xiàn)同步異步請(qǐng)求用法示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2024-01-01
基于Tensorflow讀取MNIST數(shù)據(jù)集時(shí)網(wǎng)絡(luò)超時(shí)的解決方式
這篇文章主要介紹了基于Tensorflow讀取MNIST數(shù)據(jù)集時(shí)網(wǎng)絡(luò)超時(shí)的解決方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-06-06
利用python將json數(shù)據(jù)轉(zhuǎn)換為csv格式的方法
下面小編就為大家分享一篇利用python將json數(shù)據(jù)轉(zhuǎn)換為csv格式的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-03-03
python 讀入多行數(shù)據(jù)的實(shí)例
下面小編就為大家分享一篇python 讀入多行數(shù)據(jù)的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-04-04
pycharm運(yùn)行程序時(shí)看不到任何結(jié)果顯示的解決
今天小編就為大家分享一篇pycharm運(yùn)行程序時(shí)看不到任何結(jié)果顯示的解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-02-02

