37

I am running into trouble reinstalling my nvidia drivers after the latest kernel upgrade. Normally, ubuntu-drivers handles it, but not this time.

I've done sudo apt purge -y nvidia-*, which often fixes problems when reinstalling, but that didn't help.

When I run ubuntu-drivers install, I get this error:

Traceback (most recent call last):
  File "/usr/bin/ubuntu-drivers", line 513, in <module>
    greet()
  File "/usr/lib/python3/dist-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3/dist-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/usr/bin/ubuntu-drivers", line 413, in install
    command_install(config)
  File "/usr/bin/ubuntu-drivers", line 187, in command_install
    UbuntuDrivers.detect.nvidia_desktop_pre_installation_hook(to_install)
  File "/usr/lib/python3/dist-packages/UbuntuDrivers/detect.py", line 839, in nvidia_desktop_pre_installation_hook
    with_nvidia_kms = version >= 470
UnboundLocalError: local variable 'version' referenced before assignment

Is the with_nvidia_kms message at the bottom related at all to DKMS? I had numerous problems in the past getting dkms to work in the past, before switching to ubuntu-drivers.

This was all working until a recent upgrade, which involved a kernel.

Jeff
  • 483
  • 1
  • 3
  • 5

1 Answers1

68

Had the same issue today. Fixed it by editing the /usr/lib/python3/dist-packages/UbuntuDrivers/detect.py" file and replace line 835 with this line:

version = int(package_name.split('-')[-2])

The only change I'm bringing is -2 instead of -1. Otherwise it raises a ValueError inside the try block and just doesn't give any value to the version variable.

Check out https://bugs.launchpad.net/ubuntu/+source/ubuntu-drivers-common/+bug/1993019 if that was confusing

Marc Vanhoomissen
  • 2,198
  • 6
  • 24
  • 36
Yaseen
  • 796
  • 3
  • 4