41

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
  • 523

2 Answers2

73

This relates to a bug that has been fixed, it should be solved by upgrading the ubuntu-drivers-common package.

sudo apt install --only-upgrade ubuntu-drivers-common 

Otherwise, the manual solution consists in editing the /usr/lib/python3/dist-packages/UbuntuDrivers/detect.py" file and replace line 835 with:

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.

Antonio
  • 840
Yaseen
  • 846
0

There was a bug for which a fix has now been released. You can upgrade the Ubuntu driver package with:

sudo apt install --only-upgrade ubuntu-drivers-common 
Antonio
  • 840