Contents

Install Python, Tensorflow, Pytorch, CUDA on Ubuntu 20.04 in 2022

0. Check System, CPU, GPU

1
2
$ sudo lshw -C display
$ lscpu
  • GPU: NVIDIA GeForce GTX 1060 3GB
  • CPU: Intel i7-5820K

  1. Download and use Miniconda (latest Version 3.9)

Conda is an open source package management system and environment management system that runs on Windows, macOS and Linux. Conda quickly installs, runs and updates packages and their dependencies. Conda easily creates, saves, loads and switches between environments on your local computer. It was created for Python programs, but it can package and distribute software for any language.

  • Miniconda is a free minimal installer for conda. It is a small, bootstrap version of Anaconda that includes only conda, Python, the packages they depend on, and a small number of other useful packages, including pip, zlib and a few others.
1
2
3
$ cd /Downloads
$ chmod +x ./Miniconda
$ ./Miniconda3-

Reboot the terminal

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
python --version

conda install -y jupyter

conda create --name tensorflow python=3.9

conda activate tensorflow

conda install nb_conda

conda install -c anaconda tensorflow-gpu

conda env update --file tools.yml

python -m ipykernel install --user --name tensorflow --display-name "Python 3.9 (tensorflow)"

Reboot Termimal

1
2
3
4
5
conda activate tensorflow
python
impoort tensorflow as tf
tf.__version__
len(tf.config.list_physical_devices('GPU"))

Cuda Family

1. Check CUDA version

1
$ nvidia-smi
  • NVIDIA-SMI: 470.86
  • Driver Version: 470.86
  • CUDA Version: 11.4

2. Download cuDNN

https://developer.nvidia.com/rdp/cudnn-archive

Download cuDNN v8.0.5 (Nov 9th, 2020) for CUDA 11.0

1
2
3
$ wget https://developer.download.nvidia.com/compute/cuda/11.0.3/local_installers/cuda_11.0.3_450.51.06_linux.run

$ sudo sh cuda_11.0.3_450.51.06_linux.run

3. Install cuDNN

Open a new terminal, unzip the cuDNN package just downloaded

1
~/Downloads$ tar -xvf cudnn-11.0-linux-x64-v8.0.5.39.tgz

Source

1
2
$ ls -l /usr/local/cuda
$ nano ~/.bashrc

Copy the following files into the CUDA toolkit directory

1
2
3
4
$ sudo cp cuda/include/cudnn*.h /usr/local/cuda/include
$ sudo cp -P cuda/lib64/libcudnn* /usr/local/cuda/lib64
$ sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*