NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running

I’m trying to install nvidia drivers on ubuntu 18.04 but it’s failing.

This is the output of nvidia-smi
NVIDIA-SMI has failed because it couldn’t communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running

This is the output of nvidia-settings
ERROR: NVIDIA driver is not loaded

ERROR: Unable to load info from any available system

(nvidia-settings:2115): GLib-GObject-CRITICAL **: 11:27:06.619: g_object_unref: assertion ‘G_IS_OBJECT (object)’ failed
** Message: 11:27:06.626: PRIME: No offloading required. Abort
** Message: 11:27:06.626: PRIME: is it supported? no

There is no blcklisted files for nvidia. This issue started after switching to gdm3 and switch back to xrdp based desktop.