Anaconda3 + cuda10.1 + cudnn7.6 + tensorflow 2.6 installation (Ubuntu16)

Overview of this article

  • This article records the process of setting up TensorFlow2 development environment on Ubuntu 16.04.7 LTS for reference during future reinstallation
  • The hardware is the HP dark spirit 3rd generation graphics card GTX1060 purchased in 2018, and the Ubuntu 16 lts desktop version has been installed
  • Nvidia drivers need to be installed before performing this operation. Please refer to Ubuntu 16 installing Nvidia driver (GTX1060 graphics card)
  • Check the driver information, as shown in the figure below. It can be seen that CUDA version is 10.1

Version matching

  • Go to the official website of tensorflow to check the version matching relationship, address:
  • As shown below, there are three suitable versions on my computer:


  • Note: the root account is not used for all subsequent operations
  • Download anaconda3 at: , as shown in the figure below, it can be seen that the Python corresponding to the latest official version is 3.8, which is consistent with the Python version in the TensorFlow version matching table above. Therefore, download the latest version (2021.05 at the moment)
  • Due to personal habits, my operations are from remote SSH on MacBook to Ubuntu 16 computer, which is no different from executing the command line locally. You can do it at will
  • Add executable permissions:
chmod a+x
  • function:
  • Press enter when prompted:
  • Read the document and enter yes as required:
  • Whether to initialize, enter yes:
  • Installation complete:
  • Exit ssh, log in again, and enter python to enter python in anaconda environment:
(base) will@ubuntu-hp:~$ python
Python 3.8.8 (default, Apr 13 2021, 19:58:26)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
  • Create a new conda environment named py38:
conda create -n py38 python=3.8.8
  • Activate py38:
conda activate py38
  • Install the specified version of tensorflow and specify the domestic source to speed up the download:
pip install tensorflow-gpu==2.3.0 -i
  • Install CUDA:
conda install cudatoolkit=10.1 -c
  • Installation cudnn:
conda install cudnn=7.6.5
  • After installation, verify whether TensorFlow of GPU version is successfully installed


  • Exit ssh and log in again
  • Check which conda environments are available and which are being used. Enter the command conda info --e as follows. The line with an asterisk indicates that the base environment is being used, not the py38 we want to use:
(base) will@ubuntu-hp:~$ conda info --e
# conda environments:
base                  *  /home/will/anaconda3
py38                     /home/will/anaconda3/envs/py38
  • Execute source activate py38 to switch to the py38 environment
  • Enter python directly to enter python interactive mode
  • Import tensorflow:
import tensorflow as tf
  • Display import success:
2021-10-08 23:08:55.391471: I tensorflow/stream_executor/platform/default/] Successfully opened dynamic library
  • The following code means to check whether tensorflow can be supported by CUDA. If it is supported, it will return True, otherwise it will return false:
  • The following code checks whether tensorflow can get the GPU:
  • If it can be obtained, it will return Ture, and some log information output is as follows. It can be seen that the graphics card information has been successfully obtained:
2021-10-08 23:09:34.367795: I tensorflow/stream_executor/cuda/] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-10-08 23:09:34.368110: I tensorflow/core/common_runtime/gpu/] Created TensorFlow device (/device:GPU:0 with 5088 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1060 6GB, pci bus id: 0000:01:00.0, compute capability: 6.1)
  • For comparison, the following figure shows the execution result of TensorFlow, the CPU version on MabBook:
  • At this point, the installation is complete.

Posted on Tue, 07 Dec 2021 00:22:54 -0500 by dclamp