Public bug reported: I'm having problems with an external monitor on my laptop, so I wanted to update the NVIDA drivers.
I first tried this in the "Additional Drivers" tab of "Software & Updates". I selected a newer driver, clicked "Apply Changes", and entered my password to install updates. This showed a progress bar and seemed to be working, but after a few seconds I got a blank error dialogue, with only an X button. I tried a few other driver versions with the same result. Next, I tried running `ubuntu-drivers autoinstall` from the command line. I expected this would install some drivers. Instead, I got this error trace: ``` $ sudo ubuntu-drivers autoinstall 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 ``` Looking at the code I believe the 'finally' block is trying to use the 'version' variable set in the `try`, which can only work if the try succeeds. Seeing this, I modified the script to set a default value for 'version': ``` *** /home/edward/detect.py.original 2022-10-29 15:40:49.515765835 +1100 --- /home/edward/detect.py.fixed 2022-10-29 15:39:55.383555776 +1100 *************** *** 828,839 **** --- 828,840 ---- '''Applies changes that need to happen before installing the NVIDIA drivers''' with_nvidia_kms = False # Enable KMS if nvidia >= 470 for package_name in to_install: if package_name.startswith('nvidia-driver-'): + version = -1 try: version = int(package_name.split('-')[-1]) except ValueError: pass finally: with_nvidia_kms = version >= 470 ``` With this change `ubuntu-drivers autoinstall` ran successfully and installed a bunch of packages. I can now see in Software & Updates that I am updated to the latest NVIDIA driver versions. (However my monitor isn't working yet so there may be another underlying issue.) ------------ Version information: $ lsb_release -rd Description: Ubuntu 22.04.1 LTS Release: 22.04 $ apt-cache policy ubuntu-drivers-common ubuntu-drivers-common: Installed: 1:0.9.6.1 Candidate: 1:0.9.6.1 Version table: *** 1:0.9.6.1 500 500 http://archive.ubuntu.com/ubuntu jammy/main amd64 Packages 100 /var/lib/dpkg/status ProblemType: Bug DistroRelease: Ubuntu 22.04 Package: ubuntu-drivers-common 1:0.9.6.1 [modified: usr/lib/python3/dist-packages/UbuntuDrivers/detect.py] ProcVersionSignature: Ubuntu 5.15.0-52.58-generic 5.15.60 Uname: Linux 5.15.0-52-generic x86_64 ApportVersion: 2.20.11-0ubuntu82.1 Architecture: amd64 CasperMD5CheckResult: unknown CurrentDesktop: ubuntu:GNOME Date: Sat Oct 29 15:31:57 2022 InstallationDate: Installed on 2021-04-01 (575 days ago) InstallationMedia: Ubuntu 20.04.2.0 LTS "Focal Fossa" - Release amd64 (20210209.1) SourcePackage: ubuntu-drivers-common UpgradeStatus: No upgrade log present (probably fresh install) ** Affects: ubuntu-drivers-common (Ubuntu) Importance: Undecided Status: New ** Tags: amd64 apport-bug jammy wayland-session -- You received this bug notification because you are a member of Desktop Packages, which is subscribed to ubuntu-drivers-common in Ubuntu. https://bugs.launchpad.net/bugs/1995158 Title: "ubuntu-drivers autoinstall" fails with Python UnboundLocaError Status in ubuntu-drivers-common package in Ubuntu: New Bug description: I'm having problems with an external monitor on my laptop, so I wanted to update the NVIDA drivers. I first tried this in the "Additional Drivers" tab of "Software & Updates". I selected a newer driver, clicked "Apply Changes", and entered my password to install updates. This showed a progress bar and seemed to be working, but after a few seconds I got a blank error dialogue, with only an X button. I tried a few other driver versions with the same result. Next, I tried running `ubuntu-drivers autoinstall` from the command line. I expected this would install some drivers. Instead, I got this error trace: ``` $ sudo ubuntu-drivers autoinstall 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 ``` Looking at the code I believe the 'finally' block is trying to use the 'version' variable set in the `try`, which can only work if the try succeeds. Seeing this, I modified the script to set a default value for 'version': ``` *** /home/edward/detect.py.original 2022-10-29 15:40:49.515765835 +1100 --- /home/edward/detect.py.fixed 2022-10-29 15:39:55.383555776 +1100 *************** *** 828,839 **** --- 828,840 ---- '''Applies changes that need to happen before installing the NVIDIA drivers''' with_nvidia_kms = False # Enable KMS if nvidia >= 470 for package_name in to_install: if package_name.startswith('nvidia-driver-'): + version = -1 try: version = int(package_name.split('-')[-1]) except ValueError: pass finally: with_nvidia_kms = version >= 470 ``` With this change `ubuntu-drivers autoinstall` ran successfully and installed a bunch of packages. I can now see in Software & Updates that I am updated to the latest NVIDIA driver versions. (However my monitor isn't working yet so there may be another underlying issue.) ------------ Version information: $ lsb_release -rd Description: Ubuntu 22.04.1 LTS Release: 22.04 $ apt-cache policy ubuntu-drivers-common ubuntu-drivers-common: Installed: 1:0.9.6.1 Candidate: 1:0.9.6.1 Version table: *** 1:0.9.6.1 500 500 http://archive.ubuntu.com/ubuntu jammy/main amd64 Packages 100 /var/lib/dpkg/status ProblemType: Bug DistroRelease: Ubuntu 22.04 Package: ubuntu-drivers-common 1:0.9.6.1 [modified: usr/lib/python3/dist-packages/UbuntuDrivers/detect.py] ProcVersionSignature: Ubuntu 5.15.0-52.58-generic 5.15.60 Uname: Linux 5.15.0-52-generic x86_64 ApportVersion: 2.20.11-0ubuntu82.1 Architecture: amd64 CasperMD5CheckResult: unknown CurrentDesktop: ubuntu:GNOME Date: Sat Oct 29 15:31:57 2022 InstallationDate: Installed on 2021-04-01 (575 days ago) InstallationMedia: Ubuntu 20.04.2.0 LTS "Focal Fossa" - Release amd64 (20210209.1) SourcePackage: ubuntu-drivers-common UpgradeStatus: No upgrade log present (probably fresh install) To manage notifications about this bug go to: https://bugs.launchpad.net/ubuntu/+source/ubuntu-drivers-common/+bug/1995158/+subscriptions -- Mailing list: https://launchpad.net/~desktop-packages Post to : desktop-packages@lists.launchpad.net Unsubscribe : https://launchpad.net/~desktop-packages More help : https://help.launchpad.net/ListHelp