安裝tensorflow的過程中遇到了很多大大小小的問題,下面總結(jié)一些自己的安裝流程,也算是對自己在這方面的一個總結(jié)。
centos安裝常用插件
yum -y install zip unzip vim git lrzsz wget gcc gcc-c++ python-devel java
安裝jdk8
- 使用java -version,如果你之前已經(jīng)安裝了JAVA1.6或1.7的版本,請執(zhí)行下列命令觉啊,將它們卸載。
- yum remove java
- 下載jdk相對應(yīng)的版本
- 通過rpm -ivh name.rpm進行安裝
python安裝pip
- wget https://bootstrap.pypa.io/get-pip.py --no-check-certificate
- python get-pip.py
安裝bazel
下載bazel源碼
-
方式一(推薦):
(1)直接下載bazel的對應(yīng)的版本沈贝,這里對應(yīng)的版本為0.4.5杠人,詳情參考
(2)cd bazel
(3)./compile.sh
(4)將執(zhí)行路徑/root/bazel-0.4.5-dist/output/ 添加到 $PATH 環(huán)境變量中- export BAZELHOME=/root/bazel-0.4.5-dist/output(這個路徑安裝完之后會有提示)
- export PATH=$PATH:$BAZELHOME
-
方式二:
(1)git clone https://github.com/bazelbuild/bazel.git
(2)cd bazel
(3)git checkout tags/0.1.0
(4)./compile.sh
(5)將執(zhí)行路徑/root/bazel-0.4.5-dist/output/ 添加到 $PATH 環(huán)境變量中- export BAZELHOME=/root/bazel-0.4.5-dist/output
- export PATH=
$PATH:$BAZELHOME
按esc再按shift+:輸入wq寫入,然后source /etc/profile生效
bazel -h 查看bazel信息
安裝遇到的問題
Cannot find gcc, either correct your path or set the CC environment variable.(通過yum install gcc進行安裝)
ERROR: /root/Configuration/bazel-0.4.5-dist/src/main/tools/BUILD:3:1: undeclared inclusion(s) in rule '//src/main/tools:process-wrapper'(通過pip install process-wrapper安裝)
which: no git in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin(通過yum install git安 裝)
gcc: error trying to exec 'cc1plus': execvp: No such file or directory(通過yum install gcc-c++ 安裝宋下,安裝過程中包含一個重要的庫libstdc++-devel-4.8.5-11.el7.x86_64.rpm)
/usr/local/aiconfiguration/bazel-0.4.5/src/BUILD:129:1: Executing genrule //src:embedded_tools failed: bash failed: error executing command (cd /tmp/bazel_xujO1WJE/out/execroot/bazel-0.4.5 &&
exec env - \PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
…
src/create_embedded_tools.sh: line 85: zip: command not found(這里需要特別注意嗡善,最后一句是關(guān)鍵,提示zip沒有發(fā)現(xiàn)学歧,通過yum install zip解決)
安裝numpy罩引、scipy、Pillow(進入python通過help('name')查看,如果沒有則安裝)
pip install numpy || pip install scipy || pip install pillow
支持GPU(工具包下載安裝)
- Cuda Toolkit安裝
- 下載對應(yīng)的型號
- rpm -i name.rpm
- sudo yum clean all
- sudo yum install cuda
- 安裝遇到的問題
需要安裝dkms:(1)下載dkms文件 (2)執(zhí)行:rpm -Uvh dkms-2.2.0.3-31.1.noarch.rpm - Cudnn安裝
-下載 Cudnn Toolkit包- tar xvzf cudnn-6.5-linux-x64-v2.tgz
- cp cudnn-6.5-linux-x64-v2/cudnn.h /usr/local/cuda/include
- cp cudnn-6.5-linux-x64-v2/libcudnn* /usr/local/cuda/lib64
安裝NVIDIA驅(qū)動
- 下載對應(yīng)的驅(qū)動版本,注意版本枝笨、平臺和硬件型號袁铐,例如.run包
- 通過sh name.run命令進行安裝
- 安裝遇到的問題
- ERROR: Unable to find the kernel source tree for the currently running kernel. Please make sure you have installed the kernel source files for your kernel and that they are properly configured; on Red Hat Linux systems, for example, be sure you have the 'kernel-source' or 'kernel-devel' RPM installed. If you know the correct kernel source files are installed, you may specify the kernel source path with the '--kernel-source-path' command line option
- present and prevents the NVIDIA kernel module from obtaining ownership of the NVIDIA graphics device(s), or no NVIDIA GPU installed in this system is supported by this NVIDIA Linux graphics driver release.Please see the log entries 'Kernel module load error' and 'Kernel messages' at the end of the file '/var/log/nvidia-installer.log' for more information.
- 解決方法
- 這個問題是因為通過yum安裝kernel-devel的版本號問題揭蜒,如果通過yum install kernel-devel安裝可能造成版本不支持,如果出現(xiàn)了上 述問題剔桨,可以通過yum -y install kernel-devel "kernel-devel-uname-r == $(uname -r)"命令進行安裝屉更。
- 如果通過第一個步驟重新運行sh name.run還會提示“you may specify the kernel source path with the '--kernel-source- path'”,那么你可以通過sh name.run -kernel-source-path=/usr/src/kernels/新裝的kernel-devel版本號(通過uname -r查詢)進行安裝
安裝tensorflow[注意命令源碼下劃線]
通過tensorflow源碼安裝
方式一(推薦):
(1)直接下載tensorflow的對應(yīng)的版本洒缀,這里對應(yīng)的版本為1.0.1(Source code(tar.gz))
(2)cd tensorflow
(3)./configure
(4)bazel build --config=cuda //tensorflow/tools/pip_package:build_pip_package(with CPU-only support:--config=opt or with GPU support:--config=cuda)
(5)bazel-bin/tensorflow/tools/pip_package/build_pip_package
/tmp/tensorflow_pkg(執(zhí)行完這一句會輸入一個路徑瑰谜,這個路徑里面包含了一個生成的.whl文件)
(6)pip install /tmp/tensorflow_pkg/tensorflow-1.0.1-*.whl方式二:
(1)git clone https://github.com/tensorflow/tensorflow
(2)cd tensorflow
(3)git checkout r1.0
(4)./configure
(5)bazel build --config=opt
//tensorflow/tools/pip_package:build_pip_package(with CPU-only support:--config=opt or with GPU support:--config=cuda)
(6))bazel-bin/tensorflow/tools/pip_package/build_pip_package
/tmp/tensorflow_pkg(執(zhí)行完這一句會輸入一個路徑,這個路徑里面包含了一個生成的.whl文件)
(7)pip install /tmp/tensorflow_pkg/tensorflow-1.0.1-*.whl進入python树绩,通過help('tensorflow')查看相應(yīng)信息
-
安裝需要注意的問題(支持GPU)
- 用configure腳本來配置環(huán)境信息的時候需要填[y/n]的時候需要注意了萨脑,因為默認是填n的。
- 注意TensorFlow的./configure 設(shè)置bazel option
Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native]: --config=cuda - Dou you wish to build Tensorflow with GPU support?[y/n]這個需要填y饺饭,默認是填n
- Do you wish to build TensorFlow with OpenCL support? [y/N] 如果這個選擇了y就會出現(xiàn)選擇clang砚哗、clang++的默認路徑,同 時也會出現(xiàn)Please specify the location where ComputeCpp for SYCL 1.2 is installed. [Default is /usr/local/ computecpp]: Invalid SYCL 1.2 library path. /usr/local/computecpp/lib/libComputeCpp.so cannot be found問題砰奕, openCL和cuda沒有什么直接的聯(lián)系,所以這個選項可以設(shè)置為n提鸟。
- Please specify the location where CUDA 7.0 toolkit is installed. Refer toREADME.md for more details. [default is: /usr/local/cuda]:這個路徑根據(jù)cuda安裝的路徑來設(shè)置
- Please specify the location where CUDNN 6.5 V2 library is installed. Refer toREADME.md for more details. [default is: /usr/local/cuda]: 這個路徑根據(jù)cuda安裝的路徑來設(shè)置
- Please specify a list of comma-separated Cuda compute capabilities you want to build with.
You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
Please note that each additional compute capability significantly increases your build time and binary size [Default is: "3.5,5.2"]: 6.1(這個值是要根據(jù)自己設(shè)備的军援,可參考中的CUDA-Enabled GeForce Products)
測試Tensorflow
進入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可能遇到的問題
提示:failed call to cuInit: CUDA_ERROR_UNKNOWN driver does not appear to be running on this host (localhost.localdomain): /proc/driver/nvidia/version does not exist,這個是因為源碼安裝的時候選擇了GPU支持 称勋,所以需要安裝NVIDIA驅(qū)動胸哥,具體安裝流程請看本教程的NVIDIA驅(qū)動安裝模塊。
安裝ffmpeg
-
方式一(ffmpeg源碼安裝赡鲜,推薦)
- 下載相對應(yīng)的版本
- ./configure --prefix=/usr [設(shè)置安裝路徑]
- make
- make install
- 配置環(huán)境變量
(1)export FFMPEG=/usr/local/aiconfiguration/ffmpeg/bin
(2)export PATH=$PATH:$FFMPEG - 通過ffmpeg -version查看版本信息
方式二
yum install ffmpeg
查看ffmpeg詳細信息:yum info ffmpeg(版本比較舊2.6)
-
方式二安裝遇到的問題:
yum install ffmpeg沒有匹配 ffmpeg 的軟件包(1)安裝EPEL Release
- 因為安裝需要使用其他的repo源空厌,所以需要EPEL支持yum install -y epel-release
- 如果出現(xiàn)缺少Code提示,通過rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7安裝
- 查看是否安裝成功 yum repolist
(2)安裝Nux-Dextop源
- 導(dǎo)入一個Code
sudo rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro - 安裝nux-dextop 源
sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm - 查看repo源是否安裝成功
yum repolist
卸載tensorflow
- 通過源碼安裝的卸載方法
- pip uninstall tensorflow
- 把tensorflow的源碼文件夾移除
卸載numpy银酬、scipy嘲更、Pillow
pip uninstall numpy || pip uninstall scipy || pip uninstall pillow
卸載bazel
- bazel通過源碼安裝的卸載方法
- 把bazel的源碼文件夾移除
- 把在/etc/profile里設(shè)置的環(huán)境變量移除,保存之后通過source /etc/profile生效
卸載ffmpeg
- 移除源碼安裝的文件夾(路徑根據(jù)./configure --prefix=/usr [設(shè)置安裝路徑]這個設(shè)置)
- 移除ffmpeg解壓出來的文件夾