ubuntu16.04+cuda8.0+cudnn6.0+python3.5+Tensorflow1.4_GPU

I have been building the tensorflow1.4-GPU environment under Ubuntu 16.04 for nearly a week, but the tutorials on the Internet are different, and there are always problems. I may happen to build it today, so I will record the process.


My hardware device, CPU: I5-7500, RAM: 8G, GPU: NVIDIA 1050 card.


First of all, I declare that I installed dual systems, WIN10 and Ubuntu16.04. The main reference when installing Ubuntu is this blog .


But there was a problem during the installation process, and the installation prompts "The machine starts the installer in uefi mode, but it seems that a system using bios compatibility mode already exists. If you continue to install debian in uefi mode, it may be very difficult to restart the system in other bios modes. .If you want to install in UEFI mode and do not intend to restart the existing system, there is a mandatory option here. If you want to keep the existing system bootable, do not choose to force UEFI installation". Later, I checked on the Internet and found that I was using the compatibility mode when I installed win10. Although some methods were given on the Internet, I decisively reinstalled Win10, using UEFI+GPT mode. Reference degree girl . After reinstalling Win10 and then installing Ubuntu, there is no problem.

Note: Ubuntu must set the Secure Boot in the BIOS to Disabled before installing the nividia driver.

Note: Ubuntu must set the Secure Boot in the BIOS to Disabled before installing the nividia driver.

Note: Ubuntu must set the Secure Boot in the BIOS to Disabled before installing the nividia driver.


After installing the system, update the update, delete the delete. Then prepare to install the Nvidia driver. At first, it was updated directly through the additional driver in the software update. After the update, there was unlimited login and could not enter the system. Later, I saw many tutorials on the Internet, mainly through the following steps:

1. First go to NVIDIA's official website to download according to your own hardware device


Remember where to put it after downloading.


2. Disable the nouveau driver, open the terminal and enter:

sudo gedit /etc/modprobe.d/blacklist.conf
Add the following two lines of code at the end of the pop-up text:

blacklist new
options new modeset=0
After saving and exiting, type in the terminal:

sudo update-initramfs -u
After restarting the computer, open the terminal again and enter:

lsmod | grep new
If there is no output on the screen, disabling nouveau is successful.


3. Prepare to install the nvidia driver

Before installation, first disable the X-Windows service, enter the following command:

sudo service lightdm stop
After the system executes the command, the graphics program will be closed, please don't worry , then press Ctrl + Alt + F1 to enter the command line interface, and enter the user name and password.

First open to the directory where your driver is located by commanding cd. For example, my driver is placed in the software folder under home, and the driver is renamed to nvidia-drive.run by me, and I enter the following code:

Open the folder where the driver is located:

cd ./software
Then give execute permission to the driver:

sudo chmod +x nvidia-drive.run

Start driver installation: (no-opengl-files means not to install openGL)

sudo ./nvidia-drive.run -no-opengl-files
Then follow the prompts to install, generally there is no problem, if there is a problem, go to see the Secure Boot in your BIOS is set to Disabled.

After installation, enter the command to restart:

reboot

After restarting, enter the system to check whether it is installed:

nvidia-smi # List GPU info
nvidia-settings # If a dialog box pops up normally, the installation is successful






After installing the Nvidia driver, go to download Cuda8 and cudnn6



After downloading, open the terminal and cd into the directory where the software is located to start the installation:

sudo sh ./cuda_8.0.61_375.26_linux.run
安装前会有很长一段话,直接按个q键结束,输入accept同意,之前安装过nvidia的驱动,这里询问是否安装驱动时选No,其他的按默认来就行。

安装完后声明环境变量,并写入~/.bashrc的尾部:

sudo gedit ~/.bashrc

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

然后设置环境变量和动态链接库:

sudo gedit /etc/profile
在末尾加上:

export PATH=/usr/local/cuda/bin:$PATH

保存后,创建链接文件:

sudo gedit /etc/ld.so.conf.d/cuda.conf

在末尾添加:

/usr/local/cuda-8.0/lib64

然后执行指令,生效:

sudo ldconfig

接着cd进入NVIDIA_CUDA-8.0_Samples文件夹,测试cuda的Samples:

cd /home/wz/NVIDIA_CUDA-8.0_Samples
sudo make all -j4
cd ./bin/x86_64/linux/release
sudo ./deviceQuery

显示出一些GPU信息,Result = PASS说明通过。

装完cuda8.0后在装cudnn6

首先解压,解压后cd 进入/usr/local/cuda/lib64解压文件所在根目录:

sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/


接着cd进入lib64目录下删除旧软链接,创建新软链接

cd /usr/local/cuda/lib64
sudo rm -rf libcudnn.so libcudnn.so.6
sudo ln -s libcudnn.so.6.0.21 libcudnn.so.6
sudo ln -s libcudnn.so.6 libcudnn.so


At this point, the Nvidia driver, cuda8, ​​and cudnn6 are installed, and finally restart the computer .


Since Ubuntu16.04 comes with two versions of python2.7 and python3.5, it is not allowed to install additional python. If you need to install anaconda, you can ignore this step.

Ubuntu16.04 uses the python2.7 version by default , but I need to use python3.5, so I need to modify the priority of python2.7 and 3.5. Open a terminal and enter:

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150


To change back to the default python2.7 version, enter the following command in the terminal:

sudo update-alternatives --config python



Finally install Tensorflow1.4 - GPU version

sudo pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple/   https://mirrors.tuna.tsinghua.edu.cn/tensorflow/linux/gpu/tensorflow_gpu-1.4.1-cp35-cp35m-linux_x86_64.whl

If you are prompted that pip3 is not installed, follow the prompts to install pip3.


After installation, enter python3.5 and test:




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325460656&siteId=291194637