Monday, August 9, 2021

Fixing the Tensorflow error: could not load dynamic library ''

I tried to install and run Tensorflow on a Ubuntu 20.04 laptop with a Nvidia GPU but I encountered the "could not load dynamic library ''" error message, as shown in the screenshot below.

To resolve the issue, I had to install the Nvidia kernel and Cuda 11 libraries from the Nvidia repository. The steps are outlined below.

  1. On the Ubuntu machine, open a Terminal. Type in the following commands to add the Nvidia ppa repository:

    $ wget

    $ sudo mv /etc/apt/preferences.d/cuda-repository-pin-600 && sudo apt-key adv --fetch-keys

    $ sudo add-apt-repository "deb /"

  2. In the Terminal, type in the commands to install the Nvidia kernel.

    $ sudo apt-get update && sudo apt-get install -y nvidia-kernel-source-460

  3. Finally, install Cuda with the following command.

    $ sudo apt-get -y install cuda

Subsequently when importing the Tensorflow library, the error message no longer appears.

Note: Download and install any additional missing libraries from if necessary.