首先说说安装步骤,挺简单的,就是确认pip和Python的版本
pip -V
python
如果不是最新版本就更新一下
$sudo apt-get install python-pip python-dev
然后就是安装Tensorflow了
$pip install tensorflow # Python 2.7; CPU support (no GPU support)
$pip3 install tensorflow # Python 3.n; CPU support (no GPU support)
$pip install tensorflow-gpu # Python 2.7; GPU support
$pip3 install tensorflow-gpu # Python 3.n; GPU support
如果上面的步骤不成功,就使用下面的命令:
$sudo pip install --upgradeTF_PYTHON_URL # Python 2.7
$sudo pip3 install --upgradeTF_PYTHON_URL # Python 3.N
各种版本的下载地址:
Python 2.7
CPU only:
https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.1.0-cp27-none-linux_x86_64.whlGPU support:
https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.1.0-cp27-none-linux_x86_64.whlPython 3.4
CPU only:
https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.1.0-cp34-cp34m-linux_x86_64.whlGPU support:
https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.1.0-cp34-cp34m-linux_x86_64.whlPython 3.5
CPU only:
https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.1.0-cp35-cp35m-linux_x86_64.whlGPU support:
https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.1.0-cp35-cp35m-linux_x86_64.whlPython 3.6
CPU only:
https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.1.0-cp36-cp36m-linux_x86_64.whlGPU support:
https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.1.0-cp36-cp36m-linux_x86_64.whlpython
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
如果输出Hello, TensorFlow!
则代表安装成功。
安装之后测试发现以下问题,搜了很多安装经验,我感觉应该是我之前安装的Tensorflow有冲突,虽然显示安装成功了,运行却出错。试了好多办法都不可行,无奈我把Ubuntu重新装了一下,一切就正常了。