一,安装TensorFlow
- 安装所有必备工具
sudo apt-get install python-pip python-dev python-virtualenv
- 安装TensorFlow
sudo -H pip install tensorflow
- 运行 TensorFlow
打开一个 python 终端:
$ python
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print sess.run(hello)
Hello, TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print sess.run(a+b)
42
若有提示:Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2,使用:
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' #忽略警告
二,配置pycharm和Tensorflow
- 配置pycharm解释器
在终端中输入:which python,这样将会得到Tensorflow的python解释器的路径,然后把这个路径配置pycharm中即可 (设置解释器位置:file-->setting-->Project:XXX-->Project Interpreter)
- 运行TensorFlow
在新建的pycharm的工程中新建一个python文件 ,在新建的python文件中输入:import tensorflow as tf,点击运行,如果没有错误,则说明配置成功
若有中文注释,文件开头写上#coding:utf-8