GPU not found when importing Tensorflow

I have a fresh install of Ubuntu 22.04 LTS on a machina with a GTX 1650 graphics card. I have installed the recommended nvidia drivers for this version (530). I have also installed the latest version of the cuda toolkit.

I have checked this by running the following commands:

$ nvida-smi
`+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 530.41.03              Driver Version: 530.41.03    CUDA Version: 12.1     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                  Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf            Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  NVIDIA GeForce GTX 1650         Off| 00000000:01:00.0 Off |                  N/A |
| N/A   46C    P8                3W /  N/A|      5MiB /  4096MiB |      0%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+
                                                                                         
+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|    0   N/A  N/A      1178      G   /usr/lib/xorg/Xorg                            4MiB |
+---------------------------------------------------------------------------------------+
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2023 NVIDIA Corporation
Built on Mon_Apr__3_17:16:06_PDT_2023
Cuda compilation tools, release 12.1, V12.1.105
Build cuda_12.1.r12.1/compiler.32688072_

Apart from this, I have also added CUDA to the PATH and LD_LIBRARY_PATH environment variables:

echo 'export PATH=/usr/local/cuda/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc

Then in my fresh installation I have installed the pip package manager. After doing this I have installed the python3-venv tool to create a virtual environment. To create the virtual environment I have issued the following command:

$ python3 -m venv tf-gpu
$ source tf-gpu/bin/activate

Once in the virtual environment, I have installed the tensorflow library via the following command:

$ pip install tensorflow

When I run python with the python3 command, and in the python terminal I run import tensorflow, I get the following Warning:

2023-05-26 15:49:27.326140: I tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used.

It tells me that my GPU won’t be used while I have tried to set up everything so that my GPU works, I have already tried rebooting the system and all the checks seem to work such as running:

$ echo $LD_LIBRARY_PATH

Outputs:

/usr/local/cuda/lib64

Hi @SeaSky2508,

Welcome to the Tensorflow Forum!

It seems the TensorFlow did not install in your system with correct version of CUDA and cuDNN libraries. Please have a look at the tested build configuration for the compatible CUDA, cuDNN version with the Tensorflow version.

Also, Please refer to TF install official page to install Tensorflow in your system by checking the Hardware/Software requirements for GPU setup.

Let us know if the issue still persists. Thank you.