tensorflow的安装基于python,因此需要先安装python。centos7上安装python3.5的步骤可参阅:
1. 一开始打算安装Tensorflow-gpu,但会出现一大堆问题,成功安装特别麻烦,特别不推荐
[root@ice bin]# pip3 install tensorflow-gpu
用pip3安装很简洁,唯一会出问题的是下载本身的问题,网络有时候不行的话下载到一半就会报错,如果出错的话建议换一个pip的下载源试试看。
安装CUDA9.0和cuDNN7
使用 python3命令打开一个终端,输入 import tensorflow as tf 会报错:
ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory
Failed to load the native TensorFlow runtime.
原因有3:
原因1:cuda9.0以及cudnn7未能安装或正确安装。
解决方案:安装cuda及对应cudnn,已安装情况下检查路径usr/local/cuda-9.0/lib64下是否有 libcublas.so.9.0文件
原因2:tensorflow版本与cuda不对应。
解决方案:升级tensorflow
原因3:路径未加入环境
解决方案:sudo gedit ~/.bashrc 在文档尾部加上
export LD_LIBRARY_PATH=LD_LIBRARY_PATH:/usr/local/cuda-9.0/lib64/
如果之前添加过但写法与此不同,仍然报错,请按此格式添加,本人之前写的是
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64$LD_LIBRARY_PATH,改成上边的写法就不报错了。
添加完路径之后别忘了 source ~/.banshrc
于是换个方式安装tensorflow(推荐,安装特别简洁):
1 使用pip3安装tensorflow1.9.0
[root@ice ~]# pip3 install https://files.pythonhosted.org/packages/fd/f7/934f351b5d814a0c883b7cbc9ce9cb6244d387f8bf065ddb28301f1488da/tensorflow-1.9.0-cp35-cp35m-manylinux1_x86_64.whl.9.0-cp35-cp35m-manylinux1_x86_64.whl
tensflow对应版本 https://pypi.org/project/tensorflow/#files
cp34 指对应python3.4版本;cp35指对应python3.5版本
2 安装完测试,正式开启tensorflow之旅
使用python3命令,打开一个终端,然后查看 tensorflow的版本和安装路径。
python
import tensorflow as tf
tf.__version__ 查询tensorflow的版本
tf.__path__ 查询tensorflow的安装路径
[root@ice ~]# python3
Python 3.5.2 (default, Jul 13 2018, 18:13:00)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> import numpy as np
>>> tf.__version__
'1.9.0'
>>> tf.__path__
['/usr/local/lib/python3.5/site-packages/tensorflow']
>>>
测试完毕,tensorflow已成功安装。
查看tensorflow安装版本方法2:
使用 命令 pip3 show tensorflow
[root@ice ~]# pip3 show tensorflow
Name: tensorflow
Version: 1.9.0
Summary: TensorFlow is an open source machine learning framework for everyone.
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: opensource@google.com
License: Apache 2.0
Location: /usr/local/lib/python3.5/site-packages
Requires: tensorboard, grpcio, setuptools, gast, protobuf, astor, absl-py, termcolor, wheel, six, numpy
Required-by:
[root@ice ~]#
卸载tensorflow的命令:
pip3 uninstall tensorflow
扩展:pip3命令用法:
[root@ice ice_works]# pip3 help (或 pip3 -h 或 pip3 --help)
Usage:
pip3 <command> [options]
Commands:
install Install packages.
download Download packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
list List installed packages.
show Show information about installed packages.
check Verify installed packages have compatible dependencies.
config Manage local and global configuration.
search Search PyPI for packages.
wheel Build wheels from your requirements.
hash Compute hashes of package archives.
completion A helper command used for command completion.
help Show help for commands.
General Options:
-h, --help Show help.
--isolated Run pip in an isolated mode, ignoring environment variables and user configuration.
-v, --verbose Give more output. Option is additive, and can be used up to 3 times.
-V, --version Show version and exit.
-q, --quiet Give less output. Option is additive, and can be used up to 3 times (corresponding to WARNING,
ERROR, and CRITICAL logging levels).
--log <path> Path to a verbose appending log.
--proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port.
--retries <retries> Maximum number of retries each connection should attempt (default 5 times).
--timeout <sec> Set the socket timeout (default 15 seconds).
--exists-action <action> Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort).
--trusted-host <hostname> Mark this host as trusted, even though it does not have valid or any HTTPS.
--cert <path> Path to alternate CA bundle.
--client-cert <path> Path to SSL client certificate, a single file containing the private key and the certificate in PEM
format.
--cache-dir <dir> Store the cache data in <dir>.
--no-cache-dir Disable the cache.
--disable-pip-version-check
Don't periodically check PyPI to determine whether a new version of pip is available for download.
Implied with --no-index.
--no-color Suppress colored output