Install Tensorflow-GPU in Ubuntu Anaconda

The current time is October 22, 2017, the latest version of CUDA is CUDA9, and the version of TensorFlow is 1.3. I installed CUDA9 at the beginning, but later I found that TensorFlow is not supported, someone online said that you can install TensorFlow through the source code, but I think it is too much trouble. After switching to CUDA8, there were a lot of problems with the version mismatch. Here are the version numbers of the installation packages used for this installation:

  • CUDA: Cuda - '08 - ubuntu1604-8-0 - local_8. 0.44 1 _amd64. Deb
  • cudnn: Cudnn - 8.0 - Linux - x64 - v5.1. Tar
  • Anaconda: Anaconda3-5.0.0.1 - Linux - x86_64. Sh

One, installation preparation

CUDA download

Cudnn download

Anaconda download

During the actual installation process, I found that the current latest version of Tensorflow does not support it. It took me a long time to find the corresponding installation packages mentioned above, baidu network disk sharing link, password: 8lPV

Install the NVIDIA driver

First, open Terminal and enter a command to update the app list

sudo apt-get update
Copy the code

Thanks to the support of the Linux community, we can install drivers in a very simple way:

  • Press the WIN button to open the menu

  • Then type in type to search above: Additional Drivers Open “Additional Drivers — Additional Drivers” and select the NVIDIA driver that matches your graphics card.

  • Then select Apply Changes, the installation may fail, you can continue to select Apply Changes, install a few more times.

  • After the installation is complete, select Restart

GCC down version

CUDA8.0 does not support a GCC 5.0 or higher compiler. CUDA8.0 does not support a GCC 5.0 or higher compiler. CUDA8.0 does not support a GCC 5.0 or higher compiler.

Enter the following command in terminal to reduce the GCC version to 4.9

Sudo apt-get install g++-4.9 sudo update-4.9 --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++Copy the code

Install CUDA 8.0

Go to the cudA installation package folder, right-click the terminal, and enter the following code in the terminal

Cuda 8.0 sudo DPKG -i cuda-repo-ubuntu1604-8-0-local_8.0.44-1_amd64.deb sudo apt-get update sudo apt-get install cudaCopy the code

Install CUDNN

Decompress CUDNn-8.0-linux-x64-v5.1. tar, right-click the terminal, and type the following code in the terminal

Sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64 # copying to lib64 sudo chmod a + r/usr/local/cuda/include/cudnn. H/usr/local/cuda/lib64 / libcudnn * # header file copyingCopy the code

6. Configure CUDA environment variables

Enable GPU support:

Enter the following command in terminal:

Sudo gedit ~/.bash_profile # open. Bash_profile this is the user's environment variable, not globalCopy the code

Then add at the end of the open text:

export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64"
export CUDA_HOME=/usr/local/cuda
Copy the code

After saving and closing, type the following command for the environment variable to take effect:

Source ~/.bash_profile # validates the changed environment variablesCopy the code

After the installation is complete, verify the driver by running the following commands:

  1. NVIDIA setup interface

    Nvidia-settings # Open the Nvidia Settings screenCopy the code

  1. NVIDIA GPU list

    Nvidia-smi # this command generates a list of Gpus in TerminalCopy the code

Some people on the Internet copy other people’s blog, said nvCC-V can be verified, after measurement, there is nvCC-V normal output but the driver still failed to install the phenomenon, therefore, the verification method is not credible.

Install Anaconda

Go to the anaconda installation package directory, open the terminal, and enter the installation command based on the version:

Bash Anaconda3 5.0.0.1 - Linux - x86_64. ShCopy the code

Anaconda will be installed in the ~/anaconda directory.

Finally, it asks if you want to add anaconda’s bin to the user’s environment variable, select Yes.

After the installation is successful, enter it on the terminal

source ~/.bashrc
Copy the code

Make the path added in.bashrc take effect.

Of course, you can also modify environment variables manually:

  • Start by opening the environment variable file

    gedit ~/.bashrc
    Copy the code
  • Then add the path to Anaconda3 at the end of the file

    Export PATH=/home/ Your PATH /anaconda3/bin:$PATHCopy the code
  • And finally make our changes work

    source ~/.bashrc
    Copy the code

This way, when we type Python in Terminal, we will open the default Python in Anaconda3 by default

Install tensorFlow-GPU

Create the Tensorflow runtime environment

Conda create -n tensorflow python=3.5Copy the code

Activate the environment and install tensorFlow-GPU using PIP

Source Activate tensorflow PIP install Tensorflow -gpu kerasCopy the code

After the installation is complete, we can use the following command to check whether the installation is successful:

python -c "import keras"
Copy the code

If the following output is displayed, the installation is successful

Refer to the article

Ubuntu install Tensorflow – GPU + keras

Ubuntu17.04+Nvidia GTX 1080+CUDA 9.0+cuDNN 7.0+TensorFlow 1.3

CUDA 9.0 + cuDNN 7.0 + Tensorflow source compiled