ubuntu16.04:cuda8.0+python3.5+tensorflow1.4+opencv3.2安装说明

一    安装cuda8.0

1 . 官网下载并安装对应的显卡(nvdia)驱动:http://www.nvidia.com/Download/index.aspx?lang=en-us

这里提供.run文件的驱动,且避免循环登陆问题

下载:https://pan.baidu.com/s/1i6Z3zt7 密码:5iax

可支持nvidia显卡:Tesla系列几乎所有型号,这里用的是m40 24G;

卸载掉原有驱动:sudo apt-get remove --purge nvidia*

禁用nouveau:vim /etc/modprobe.d/blacklist.conf   

在最后一行添加:blacklist nouveau

执行:sudo update-initramfs -u

重启后执行:lsmod | grep nouveau
没有输出即屏蔽好了。

禁用X服务:sudo /etc/init.d/lightdm stop

进入命令行界面:Ctrl-Alt+F1

执行:sudo chmod a+x NVIDIA-Linux-x86_64-384.66.run

sudo ./NVIDIA-Linux-x86_64-384.66.run –no-opengl-files

后面一定要加上–no-opengl-files

完成并重启。

2 . 安装cuda8.0的run文件

可以选择deb文件:

下载cuda8.0:cuda-repo-ubuntu1604-8-0-local_8.0.44-1_amd64.deb

链接:https://pan.baidu.com/s/1c2Ndg4o 密码:5nqv

或者:https://developer.nvidia.com/cuda-downloads

不过建议用run文件:

链接:https://pan.baidu.com/s/1dou7ts  密码:dune

然后:sudo chmod +x cuda_8.0.61_375.26_linux.run

sudo ./cuda_8.0.61_375.26_linux.run

然后根据命令行提示安装;按q退出条款浏览或者按空格直到条款末尾,输入accept接受条款;输入n不安装nvidia图像驱动,前面已经安装好驱动;

输入y安装cuda 8.0 toolkit;回车确认cuda默认安装路径(/usr/local/cuda-8.0);输入n不安装CUDA 8.0 Samples;结束。

在PATH变量中加入/usr/local/cuda-8.0/bin  :

gedit ~/.bashrc:末尾加上

export PATH=/usr/local/cuda-8.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH 

重启:sudo reboot

命令行执行nvcc -V查看,出现下列文字表示安装成功:

qdu@qdu:~$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Sun_Sep__4_22:14:01_CDT_2016
Cuda compilation tools, release 8.0, V8.0.44

3 . 编译例程(可以省略)

cd /usr/local/cuda-8.0/samples

sudo make

编译完成后生成的可执行文件将会位于上述文件夹下的bin目录下。运行一个例子看看:

cd bin/x86_64/linux/release

./deviceQuery    ----------会提示pass

二  安装python3.5

不要卸载自带python2.7

sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get install python3.5 
sudo cp /usr/bin/python /usr/bin/python_bak 
sudo rm /usr/bin/python 
sudo ln -s /usr/bin/python3.5 /usr/bin/python 
python -V  ---查看python版本

三 安装PIP

wget https://bootstrap.pypa.io/get-pip.py --no-check-certificate
sudo python get-pip.py

四 安装cudnn下载cudnn8.0-linux-x64-v6.0.tgz

下载:https://pan.baidu.com/s/1hs23HrA

解压后:
cd ~/下载/cuda/include 

sudo cp *.h /usr/local/cuda/include/ 

cd ~/下载/cuda/lib64 

sudo cp libcudnn* /usr/local/cuda/lib64/ 

sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn* 

sudo ln -s libcudnn.so.6.0.21 libcudnn.so.6 

sudo ln -s libcudnn.so.6 libcudnn.so 

注:如果有问题请把目录中的/usr/local/cuda改为/usr/local/cuda-8.0重新执行一遍

libcudnn.so.6.0.21,libcudnn.so.6 ,libcudnn.so  是一个文件不同名字

五 安装tensorflow1.4

下载:tensorflow_gpu-1.4.0-cp35-cp35m-manylinux1_x86_64.whl

链接:https://pypi.python.org/pypi/tensorflow-gpu/1.4.0

安装:sudo pip install tensorflow_gpu-1.4.0-cp35-cp35m-manylinux1_x86_64.whl

测试:

qdu@qdu:~$ python
Python 3.5.2 (default, Sep 14 2017, 22:51:06)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> tf.__version__
'1.4.0'
>>>

六  安装opencv3.2

Script:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential cmake pkg-config

sudo apt-get install libjpeg8-dev libtiff5-dev libjasper-dev libpng12-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev
sudo apt-get install libgtk-3-dev
sudo apt-get install libatlas-base-dev gfortran
sudo apt-get install python2.7-dev python3.5-dev

cd ~
wget -O opencv.zip https://github.com/Itseez/opencv/archive/3.2.0.zip
unzip opencv.zip
wget -O opencv_contrib.zip https://github.com/Itseez/opencv_contrib/archive/3.2.0.zip
unzip opencv_contrib.zip

cd ~/opencv-3.2.0/
mkdir build
cd build

cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D INSTALL_C_EXAMPLES=OFF \
    -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.2.0/modules \
    -D PYTHON_EXECUTABLE=/usr/bin/python3.5 \
    -D PYTHON3_INCLUDE=/usr/include/python3.5 \
    -D PYTHON3_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.5m.so \
    -D PYTHON3_PACKAGES_PATH=/usr/local/lib/python3.5/site-packages \
    -D PYTHON3_NUMPY_INCLUDE_DIRS=/usr/local/lib/python3/dist-packages/numpy/core/include \
    -D BUILD_EXAMPLES=ON ..

make -j8
sudo make install
sudo ldconfig

cd /usr/local/lib/python3.5/site-packages/
sudo mv cv2.cpython-35m-x86_64-linux-gnu.so cv2.so

If not done already, add /usr/local/lib/python3.5/site-packages/ to PYTHONPATH and PyCharm Interpreter Paths:

Add this line to ~/.bashrc:
export PYTHONPATH="${PYTHONPATH}:/usr/local/lib/python3.5/site-packages"

测试:

qdu@qdu:~$ python
Python 3.5.2 (default, Sep 14 2017, 22:51:06)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import cv2
>>>
参考链接:https://github.com/anson0910/Ubuntu16.04_python3_openCV3.2.0



你可能感兴趣的:(ubuntu16.04:cuda8.0+python3.5+tensorflow1.4+opencv3.2安装说明)