Ubuntu16.04安装tensorflow
1.采用源码安装的方式安装cuda8.0 https://developer.nvidia.com/cuda-downloads
sudo chmod +x cuda_8.0.61_375.26_linux.run
sudo ./cuda_8.0.61_375.26_linux.run ,在安装的同时选择不安装驱动
然后降低gcc版本
sudo apt-get install g++-4.9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 20
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 10
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set cc /usr/bin/gcc
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --set c++ /usr/bin/g++
2. 安装完毕后安装375.26的nvidia显卡驱动
到nvidia的官网下载对应的驱动程序NVIDIA-Linux-x86_64-375.26.run 之后,
Ubuntu系统集成的显卡驱动程序是nouveau,它是第三方为NVIDIA开发的开源驱动,我们需要先将其屏蔽才能安装NVIDIA官方驱动。
将驱动添加到黑名单blacklist.conf中,但是由于该文件的属性不允许修改。所以需要先修改文件属性。
查看属性
$sudo ls -lh /etc/modprobe.d/blacklist.conf
修改属性
$sudo chmod 666 /etc/modprobe.d/blacklist.conf
用gedit编辑器打开
$sudo gedit /etc/modprobe.d/blacklist.conf
在该文件后添加一下几行:
blacklist vga16fb
blacklist nouveau
blacklist rivafb
blacklist rivatv
blacklist nvidiafb
先按Ctrl + Alt + F1到控制台,关闭当前图形环境
$sudo service lightdm stop
再安装驱动程序
$sudo chmod +x NVIDIA-Linux-x86_64-375.26.run
sudo ./NVIDIA-Linux-x86_64-375.26.run -no-opengl-files
最后重新启动图形环境
$sudo service lightdm start
3. 安装cudnn
tar xvzf cudnn-8.0-linux-x64-v5.0-ga.tgz
sudo cp cuda/include/cudnn.h /usr/local/cuda-8.0/include###(复制)
sudo cp cuda/lib64/libcudnn* /usr/local/cuda-8.0/lib64###(复制)
sudo chmod a+r /usr/local/cuda-8.0/include/cudnn.h /usr/local/cuda-8.0/lib64/libcudnn*
然后配置环境变量
sudo gedit ~/.bash_profile
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda-8.0/lib64:/usr/local/cuda-8.0/extras/CUPTI/lib64"
export CUDA_HOME=/usr/local/cuda-8.0
安装其他库
sudo apt-get install python-pip python-dev
4.安装bazel
先配置bazel的环境变量,https://docs.bazel.build/versions/master/install-ubuntu.html
1. Install JDK 8
Install JDK 8 by using:
sudo apt-get install openjdk-8-jdk
2. Add Bazel distribution URI as a package source (one time setup)
echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -
3. Install and update Bazel
sudo apt-get update && sudo apt-get install bazel
然后下载bazel
https://github.com/bazelbuild/bazel/releases
下载的是
bazel-0.5.2-installer-linux-x86_64.sh
进行安装
sudo chmod +x bazel-0.5.2-installer-linux-x86_64.sh
sudo ./bazel-0.5.2-installer-linux-x86_64.sh
--user
会提示输入 source /home/zhao/.bazel/bin/bazel-complete.bash
5.安装第三方库
sudo apt-get install python-numpy swig python-dev python-wheel #安装第三方库
sudo apt-get install git
git clone git://github.com/numpy/numpy.git numpy
6.安装tenorflow
git clone https://github.com/tensorflow/tensorflow
cd ~/tensorflow #切换到tensorflow文件夹
./configure
注意要选择5.0
/usr/local/cuda-8.0
/usr/local/cuda
cd ~/tensorflow
bazel build -c opt //tensorflow/tools/pip_package:build_pip_package
bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
sudo pip install /home/***(你自己的用户名)/Desktop/tensorflow-0.10.0-cp2-none-any.whl
bazel build -c opt //tensorflow/tools/pip_package:build_pip_package
# To build with GPU support:
bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
mkdir _python_build
cd _python_build
ln -s ../bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles/org_tensorflow/* .
ln -s ../tensorflow/tools/pip_package/* . python setup.py develop