Score:6

sudo ubuntu-drivers autoinstall: UnboundLocalError: local variable 'version' referenced before assignment

cn flag

I recently re-installed my wife's XUbuntu 22 machine. Previously we used the NVidia driver package from the NVidia website, especially after a bit of a f&%k up last year where the official repo version broke due to broken dependencies.

This time I thought I would give the repo version another go, especially since my wife is scared of re-installing the graphics drivers after a kernel update - and it is a real nuisance.

As per the guide I found online I ran the command sudo ubuntu-drivers autoinstall. The result was:

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 432, in autoinstall
    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

I manually installed the 515 drivers repo package, but it does not seem to include the 32 bit drivers, and now Steam, among other things, doesn't work.

AlastairG avatar
cn flag
I just listed packages and I do appear to have `libnvidia-gl-515:i386`, so maybe that isn't why Steam isn't working. I would like to get rid of the error though.
Mohamed Elgazar avatar
as flag
It looks like the ubuntu-drivers command is having some trouble. You might want to try running it again with the --debug option to see if that provides any more information. Alternatively, you can try manually installing the drivers from the NVIDIA website. Just download the drivers for your specific graphics card and follow the instructions on the website.
AlastairG avatar
cn flag
@Mohamed, what you suggest is what I used to do and am trying to avoid doing.
Score:6
tz flag

The reason for the error is the bug in the installer. The more detailed explanation could be found on nvidia forum. If you want to use command line for driver installation, you could run such a command to get possible driver versions:

sudo ubuntu-drivers devices

Then you can manually choose the version you want from the list, but use it without -open at the end (this is the reason for the error). So, instead of nvidia-driver-515-open use nvidia-driver-515 and run:

sudo apt install nvidia-driver-515
Score:2
tm flag

Had the same issue, fixed it by installing the driver from "Software & Updates" -> "Additional Drivers" & then the newest Nvidia Driver. After that running sudo ubuntu-driver autoinstall gave me "All the available drivers are already installed."

AlastairG avatar
cn flag
That works, but I really prefer using the command line. I would still like to get the `ubuntu-drivers` command to work without crashing. Is it a bug in the command? The config? Something I did? Something I need to raise a bug report on?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.