最近重装系统,安装了tensorflow的配置环境
总结一下。
参考资料
http://blog.csdn.net/ZWX2445205419/article/details/69429518
http://blog.csdn.net/u013294888/article/details/56666023
http://www.2cto.com/kf/201612/578337.html
http://blog.csdn.net/10km/article/details/61915535
第一步 安装NIVDIA驱动
1.0 关闭secure boot;
这一步是最关键的,否则后面都无法安装!!!!
1.1 查询Nvidia显卡驱动信息
查看显卡的型号
lspci | grep -i vga
lspci | grep -i nvidia
然后看显卡驱动
lsmod | grep -i nvidia
#查看你的系统信息
uname -m && cat /etc/*release
# 查看核
uname -r
# 为当前核安装kernel headers和development packages
sudo apt-get install linux-headers-$(uname -r)
1.2拉黑nouveau
ubuntu自带的nouveau驱动会影响cuda安装,不当操作会导致黑屏和登陆循环
终端中运行:
lsmod | grep nouveau
如果有输出则代表nouveau正在加载。
关闭方法
创建vim /etc/modprobe.d/blacklist-nouveau.conf,
写入:
blacklist nouveau
options nouveau modeset=0
拉黑nouveau
这个显卡驱动,需要编辑配置文件并添加配置参数:按Ctrl+Alt+T打开终端,输入以下命令(#
开头的内容是注释不会被执行):
sudo gedit /etc/modprobe.d/blacklist.conf # 用gedit编辑器打开配置文件
在文件末尾追加如下内容:
blacklist nouveau
1.3 卸载之前安装的Nvidia显卡驱动安装
sudo apt-get remove –purge nvidia-*
1.4 安装NVIDIA驱动
在ubuntu16.04中,更换驱动非常方便,去
系统设置->软件更新->附加驱动->切换到最新的NVIDIA驱动即可。应用更改->重启
验证安装是否成功
终端输入nvidia-smi
如果出现了你的GPU列表,则说明驱动安装成功了。
另外也可以输入nvidia-settings
出现安装驱动完成
第二部 安装CUDA 8.0
2.1 命令行安装.run文件
下载地址 https://developer.nvidia.com/cuda-toolkit-archive
sudo sh cuda_8.0.61_375.26_linux.run
安装过程:
Do you accept the previously read EULA?
accept/decline/quit: accept
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 375.26?
(y)es/(n)o/(q)uit: n(这一步选择n,其他选择y或者按enter)
Install the CUDA 8.0 Toolkit?
(y)es/(n)o/(q)uit: y
Enter Toolkit Location
[ default is /usr/local/cuda-8.0 ]:
Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y
Install the CUDA 8.0 Samples?
(y)es/(n)o/(q)uit: y
Enter CUDA Samples Location
[ default is /home/maddock ]:
Installing the CUDA Toolkit in /usr/local/cuda-8.0 ...
Installing the CUDA Samples in /home/maddock ...
Copying samples to /home/maddock/NVIDIA_CUDA-8.0_Samples now...
Finished copying samples.
===========
= Summary =
===========
Driver: Not Selected
Toolkit: Installed in /usr/local/cuda-8.0
Samples: Installed in /home/maddock
Please make sure that
- PATH includes /usr/local/cuda-8.0/bin
- LD_LIBRARY_PATH includes /usr/local/cuda-8.0/lib64, or, add /usr/local/cuda-8.0/lib64 to /etc/ld.so.conf and run ldconfig as root
To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-8.0/bin
Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-8.0/doc/pdf for detailed information on setting up CUDA.
***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 361.00 is required for CUDA 8.0 functionality to work.
To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
sudo <CudaInstaller>.run -silent -driver
Logfile is /tmp/cuda_install_20707.log
安装cuda时可能有下面的信息
Installing the CUDA Toolkit in /usr/local/cuda-8.0 …
Missing recommended library: libGLU.so
Missing recommended library: libX11.so
Missing recommended library: libXi.so
Missing recommended library: libXmu.so
解决方法
sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev
2.2 设置环境变量
编辑home目录下面.bashrc文件
sudo vim ~/.bashrc
输入下面内容
export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda8.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64/
使得环境变量生效
source ~/.bashrc
2.3测试CUDA的sammples
运行如下的命令
cd /usr/local/cuda-8.0/samples
sudo make all
cd ./1_Utilities/deviceQuery
sudo make
./deviceQuery
测试过程中
/usr/bin/ld: 找不到 -lnvcuvid
collect2: error: ld returned 1 exit status
Makefile:381: recipe for target 'cudaDecodeGL' failed
参考网站
https://askubuntu.com/questions/891003/failure-in-running-cuda-sample-after-cuda-8-0-installation
http://www.caffecn.cn/?/question/1109
将 UBUNTU_PKG_NAME = "nvidia-367" 换成UBUNTU_PKG_NAME = "nvidia-375"
执行sudo sed -i "s/nvidia-367/nvidia-375/g" `grep nvidia-367 -rl .`
接着sudo make
全部编译完成后, 进入 samples/bin/x86_64/Linux/release,
sudo下运行deviceQuery
sudo ./deviceQuery
如何查看CUDA的版本
nvcc -V
第三部分安装cuDNN
3.1 cuDNN安装
下载下来以后,发现是一个tgz的压缩包,使用tar进行解压
tar -xvf cudnn-8.0-linux-x64-v5.1.tgz
安装cuDNN比较简单,解压后把相应的文件拷贝到对应的CUDA目录下即可
sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/
sudo chmod a+r /usr/local/cuda/include/cudnn.h
sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
3.2 更改动态文件链接
cd /usr/local/cuda/lib64/
sudo rm -rf libcudnn.so libcudnn.so.5 #删除原有动态文件
以下的两步设置软连接时
一定要注意自己电脑的/usr/local/cuda/lib64/下的libcudnn.so.5.1.10名字,
有的可能是libcudnn.so.5.0.5等,要依据自己的电脑上的文件来定
sudo ln -s libcudnn.so.5.1.10 libcudnn.so.5 #生成软链接
sudo ln -s libcudnn.so.5 libcudnn.so #生成软链接
3.3 cuDNN后续升级
(1)重复3.1的步骤
(2)
cd /usr/local/cuda/lib64/
sudo rm -rf libcudnn.so libcudnn.so.5 #删除原有动态文件
sudo ln -s libcudnn.so.5.1.x libcudnn.so.5 #生成软链接
sudo ln -s libcudnn.so.5 libcudnn.so #生成软链接
解释,根据升级对应的版本号修改x符号
第四部分 安装tensorflow
极客安装
http://wiki.jikexueyuan.com/project/tensorflow-zh/get_started/os_setup.html
https://morvanzhou.github.io/tutorials/machine-learning/tensorflow/1-2-install
http://blog.csdn.net/u014516389/article/details/72818155/
4.1安装pip
使用pip或pip3直接安装tensorflow
首先安装其依赖项
$ sudo apt-get install python-pip python-dev # for Python 2.7
$ sudo apt-get install python3-pip python3-dev # for Python 3.n
检查pip以及python的版本
输入pip -V && python -V出现
pip 8.1.1 from /usr/lib/python2.7/dist-packages (python 2.7)
Python 2.7.12
4.2 安装TF
(1) 安装GPU最新的版本
一定要加上sudo安装在系统python目录下面
sudo pip install tensorflow-gpu
$ sudo pip show tensorflow-gpu
Name: tensorflow-gpu
Version: 1.4.0
Summary: TensorFlow helps the tensors flow
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: opensource@google.com
License: Apache 2.0
Location: /usr/local/lib/python2.7/dist-packages
Requires: mock, tensorflow-tensorboard, numpy, backports.weakref, wheel, six, protobuf, enum34
(2)安装tensorflow指定的版本
sudo pip install tensorflow-gpu==1.2.0
$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl
4.3 TF升级
1.我下载的是当前的最新版本,后期如果需要新的版本,比如升级到1.5.0
$ pip install --upgrade tensorflow-gpu==1.5.0
2.也可以登陆https://storage.googleapis.com/tensorflow/,看是否有更新,然后先卸载,再将对应位置更改一下即可,但须卸载旧的版本
$ sudo pip uninstall tensorflow-gpu
这样TensorFlow的环境就安装完成了
测试
import tensorflow as tf
hello=tf.constant('Hello, TensorFlow')
sess=tf.Session()
print(sess.run(hello))
Hello, TensorFlow!