Failed to install nvidia drivers - apt --fix-broken install not working

I have tried installing drivers for my GeForce 840M graphics card.
I tried running:

sudo ubuntu-drivers autoinstall

. It worked until I got this:

The following packages have unmet dependencies:
 libnvidia-ifr1-430 : Depends: libnvidia-gl-430 but it is not installed
 libnvidia-ifr1-430:i386 : Depends: libnvidia-gl-430:i386 but it is not installed
 nvidia-driver-430 : Depends: libnvidia-gl-430 (= 430.09-0ubuntu0~gpu19.04.1) but it is not installed
                     Recommends: nvidia-settings but it is not installed
                     Recommends: nvidia-prime (>= 0.8) but it is not installed
                     Recommends: libnvidia-gl-430:i386 (= 430.09-0ubuntu0~gpu19.04.1)
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

I tried running

sudo apt --fix-broken install

and got this error:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following package was automatically installed and is no longer required:
  libbz2-1.0:i386
Use 'sudo apt autoremove' to remove it.
The following additional packages will be installed:
  libnvidia-gl-430 libnvidia-gl-430:i386
The following NEW packages will be installed:
  libnvidia-gl-430 libnvidia-gl-430:i386
0 upgraded, 2 newly installed, 0 to remove and 2 not upgraded.
17 not fully installed or removed.
Need to get 0 B/50,0 MB of archives.
After this operation, 239 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 320226 files and directories currently installed.)
Preparing to unpack .../libnvidia-gl-430_430.09-0ubuntu0~gpu19.04.1_i386.deb ...
dpkg-query: no packages found matching libnvidia-gl-418
diversion of /usr/lib/i386-linux-gnu/libGL.so.1 to /usr/lib/i386-linux-gnu/libGL.so.1.distrib by nvidia-340
dpkg-divert: error: mismatch on package
  when removing 'diversion of /usr/lib/i386-linux-gnu/libGL.so.1 by libnvidia-gl-430'
  found 'diversion of /usr/lib/i386-linux-gnu/libGL.so.1 to /usr/lib/i386-linux-gnu/libGL.so.1.distrib by nvidia-340'
dpkg: error processing archive /var/cache/apt/archives/libnvidia-gl-430_430.09-0ubuntu0~gpu19.04.1_i386.deb (--unpack):
 new libnvidia-gl-430:i386 package pre-installation script subprocess returned error exit status 2
Preparing to unpack .../libnvidia-gl-430_430.09-0ubuntu0~gpu19.04.1_amd64.deb ...
dpkg-query: no packages found matching libnvidia-gl-418
diversion of /usr/lib/x86_64-linux-gnu/libGL.so.1 to /usr/lib/x86_64-linux-gnu/libGL.so.1.distrib by nvidia-340
dpkg-divert: error: mismatch on package
  when removing 'diversion of /usr/lib/x86_64-linux-gnu/libGL.so.1 by libnvidia-gl-430'
  found 'diversion of /usr/lib/x86_64-linux-gnu/libGL.so.1 to /usr/lib/x86_64-linux-gnu/libGL.so.1.distrib by nvidia-340'
dpkg: error processing archive /var/cache/apt/archives/libnvidia-gl-430_430.09-0ubuntu0~gpu19.04.1_amd64.deb (--unpack):
 new libnvidia-gl-430:amd64 package pre-installation script subprocess returned error exit status 2
Errors were encountered while processing:
 /var/cache/apt/archives/libnvidia-gl-430_430.09-0ubuntu0~gpu19.04.1_i386.deb
 /var/cache/apt/archives/libnvidia-gl-430_430.09-0ubuntu0~gpu19.04.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

It looks like I am stuck in this loop…

I fixed it thanks to this link: [SOLVED] nvidia errors during driver update - Linux Mint Forums

HI

i am using HP pavillion Notebook with Nvidia graphics card 840M, i update my driver to the recent version and now i am getting an (code 43) error for nvidia driver i tried uninstalling drivers, rebooting system, installed new windows 10 os, updated BIOS settings i tried everything available in the internet and ended in failure

Since you already reinstalled, code 43 means your gpu is broken. Sorry.

I had a similar problem and fixed it by following [Solved] “sub process usr bin dpkg returned an error code 1″ Error in Ubuntu