The ubuntu system uses Anaconda to install the tensorflow-gpu environment

1. Environment configuration version information:

When installing [tensorflow] -gpu, special attention should be paid to the adaptation information of tensorflow-gpu, Python, CUDA, and cuDNN versions. If the version does not match, the installation of tensorflow-gpu will fail . The software version information selected in this installation tutorial is: ubuntu18.04 + Anaconda3 .5.3.1 + Python3.6.12 + tensorflow-gpu2.2.0 + CUDA10.1 + cuDNN7.6.5

For more version adaptation information, please refer to the official website: [https://tensorflow.google.cn/install/source_windows]

2. Installation steps:

1. Install Anaconda:

/a745233700/article/details/109376667

2. Use Anaconda to create a Python environment:

(1) Create an environment named py36 based on python3.6

conda create -n py36 python=3.6.12

(2) Activate the environment:

conda activate py36

3. Install tensorflow-gpu 2.2.0:

pip install tensorflow-gpu==2.2.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

4. Install CUDA 10.1 :

conda install cudatoolkit = 10.1 -c https: / /mirrors.tuna.tsinghua.edu.cn/anaconda / pkgs / free / linux-64 /

5. Install cuDNN 7.6.5:

conda install cudnn = 7 . 6 . 5

6. Test whether the installation is successful:

import tensorflow as tf
 #Check whether tensorflow is supported by CUDA, if the installation is successful, it will display true , otherwise it will be false
tf.test.is_built_with_cuda()
#Check whether tensorflow can get the GPU, if the installation is successful, it will display true , otherwise it will be false 
tf.test.is_gpu_available()

3. Problems encountered and solutions:

1. After installing Anaconda, there will be a default base running environment. Can you install tensorflow directly in the default environment? Or do I have to create a new operating environment?

Do not use the default environment to install directly. It is best to use different environments for different tasks. Installing new modules in the default environment may conflict, causing [Anaconda] to crash, and eventually need to be uninstalled and reinstalled.
In the process of installing tensorflow- [gpu] 2.2.0 in the default base operating environment, due to the need to update the Python version, it will cause conflicts with the original modules and cause Anaconda to crash.

2. The result of tf.test.is_gpu_available() is false :

(1) First, ensure the adaptation information of the tensorflow-gpu, Python, CUDA, and cuDNN versions. If not, uninstall the incompatible version and reinstall it. If the version is suitable, go to step (2);

(2) Configure the environment variables of cuda:

Open ~/.bashrc (vim ~/.bashrc) and configure the following environment variables:

export CUDA_HOME=/root/anaconda3/pkgs/cudatoolkit-10.1.243-h6bb024c_0/lib
export PATH=$PATH:$CUDA_HOME/bin

CUDA_HOME points to the installation path of the cuda package. The packages installed by anaconda are placed in the /root/anaconda3/pkgs path by default.

(3) Update environment variables:

source ~/.bashrc

Leave a Comment

Your email address will not be published. Required fields are marked *