环境准备

Ubuntu(Windows环境下忽略)

  1. sudo apt-get update
  2. sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg-dev libswscale-dev libtiff5-dev:i386 libtiff5-dev
  3. sudo apt-get install autoconf automake libtool

GPU环境CUDA和CuDNN安装(CPU版本忽略)

注意:匹配TensorFlow所支持的版本再下载

参考安装教程

开始安装:

1:Anaconda安装

包含了conda、Python等180多个科学包及其依赖项,功能十分强大

https://www.anaconda.com/distribution/#download-section

2: 创建Python环境

  1. conda create -n test python=3.7

3: 激活conda

  1. conda activate test

4: 安装TensorFlow

  1. python -m pip install --upgrade pip
  2. CPU版本:pip install --ignore-installed --upgrade tensorflow
  3. GPU版本:pip install --ignore-installed --upgrade tensorflow-gpu

至此,tensorflow的安装完成,测试代码:

  1. import tensorflow as tf
  2. hello = tf.constant('Hello, TensorFlow!')
  3. sess = tf.Session()
  4. print(sess.run(hello))