TensorFlow Official Installation: https://www.tensorflow.org/install/pip
Note: TensorFlow installation guide is not updated to install 20.04 on Ubuntu
System requirements (what I installed on):
- Python 3.8
- Ubuntu 20.04
0. Hardware requirements: GPU support
TensorFlow Official GPU support (not updated, only supports up to Ubuntu 18.04): https://www.tensorflow.org/install/gpu
pip install tensorflow
Previous cuda .deb
files https://developer.download.nvidia.com/compute/cuda/repos/
Previous machine learning .deb
files
https://developer.download.nvidia.com/compute/machine-learning/repos/
My process of installing TensorFlow: using latest cuda 11.2
# Add NVIDIA package repositories
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin
sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/7fa2af80.pub
sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /"
sudo apt-get update
wget http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu2004/x86_64/nvidia-machine-learning-repo-ubuntu2004_1.0.0-1_amd64.deb
sudo apt install ./nvidia-machine-learning-repo-ubuntu2004_1.0.0-1_amd64.deb
sudo apt-get update
# Install NVIDIA driver
sudo apt-get install nvidia-driver-460
# Reboot. Check that GPUs are visible using the command: nvidia-smi
wget http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/libnvinfer7_7.2.3-1+cuda11.1_amd64.deb
sudo apt install ./libnvinfer7_7.2.3-1+cuda11.1_amd64.deb _7.2.3-1+cuda11.1_amd64.deb
sudo apt-get update
# Install development and runtime libraries (~4GB)
sudo apt-get install cuda-11-2 libcudnn8 libcudnn8-dev
# Install TensorRT. Requires that libcudnn8 is installed above.
# sudo apt-get install -y libnvinfer7 libnvinfer-dev libnvinfer-plugin7 THIS WONT WORK
wget https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/libnvinfer-dev_7.2.3-1+cuda11.1_amd64.deb
wget https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/libnvinfer-plugin7_7.2.3-1+cuda11.1_amd64.deb
sudo apt install ./libnvinfer-dev_7.2.3-1+cuda11.1_amd64.deb ./libnvinfer-plugin7_7.2.3-1+cuda11.1_amd64.deb
# Create symbolic link for libcusolver.so.10
sudo ln -s /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcusolver.so.11 /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcusolver.so.10
for your convenience I have copied the rest of TensorFlow installation process
1. Install Python
Check if you have Python environment using
python --version
pip3 --version
If already installed, move to step 2, otherwise install Python , the pip package manager , and venv :
sudo apt update
sudo apt install python3-dev python3-pip python3-venv
If not in a virtual environment, use python3 -m pip for the commands below. This ensures that you upgrade and use the Python pip instead of the system pip.
2. Create a virtual environment (recommended)
Create a new virtual environment by choosing a Python interpreter and making a ./venv
directory to hold it:
python3 -m venv --system-site-packages ./venv
Activate the virtual environment using a shell-specific command:
source ./venv/bin/activate # sh, bash, or zsh
. ./venv/bin/activate.fish # fish
source ./venv/bin/activate.csh # csh or tcsh
When the virtual environment is active, your shell prompt is prefixed with (venv).
Install packages within a virtual environment without affecting the host system setup. Start by upgrading pip:
pip install --upgrade pip
pip list # show packages installed within the virtual environment
And to exit the virtual environment later:
deactivate # don't exit until you're done using TensorFlow
3. Install TensorFlow pip package
Choose one of the following TensorFlow packages to install from PyPI:
tensorflow
—Latest stable release with CPU and GPU support (Ubuntu and Windows).
tf-nightly
—Preview build (unstable). Ubuntu and Windows include GPU support.
tensorflow ==1.15
—The final version of TensorFlow 1.x.
Virtual environment install
pip install --upgrade tensorflow
System install
pip3 install --user --upgrade tensorflow # install in $HOME
Verify the install:
python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"