安装 NVIDIA 驱动程序 - “sudo ubuntu-drivers autoinstall”出现 UnboundLocalError?

安装 NVIDIA 驱动程序 - “sudo ubuntu-drivers autoinstall”出现 UnboundLocalError?

导游对于我正在使用的 60 分钟旧版 Ubuntu 22.04 系统,它会告诉我是否同意运行的建议sudo ubuntu-drivers autoinstall。但这给了我一个错误。

peter@peter-NBINF-O5-12R5N-54:~$ sudo ubuntu-drivers autoinstall
[sudo] password for peter: 
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

如果我使用以下命令打开该文件,我可以看到完整的功能nano

def nvidia_desktop_pre_installation_hook(to_install):
    '''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-'):
            try:
                version = int(package_name.split('-')[-1])
            except ValueError:
                pass
            finally:
                with_nvidia_kms = version >= 470

    if with_nvidia_kms:
        set_nvidia_kms(1)

我应该怎么办?

答案1

下一行导游已经基本上说明了如何解决自动安装程序的问题:

# Use the 'recommended' driver from the output of the earlier step, running `ubuntu-drivers devices`
sudo apt install nvidia-driver-530-open

所以这基本上是 PEBCAK(虽然我不明白为什么自动安装程序脚本将来不能对 NVIDIA KMS 做出更好的猜测,无论它是什么,或者正确解析带有 -server 或 -open 后缀的 nvidia-driver 字符串,也许通过获取拆分字符串的第 [2] 个元素而不是最后一个元素,也许将来会这样做)。

为了补充背景信息,我之前的步骤如下:

peter@peter-NBINF-O5-12R5N-54:~$ ubuntu-drivers devices
== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
modalias : pci:v000010DEd000025A2sv00001D05sd00001178bc03sc00i00
vendor   : NVIDIA Corporation
model    : GA107M [GeForce RTX 3050 Mobile]
driver   : nvidia-driver-515-open - distro non-free
driver   : nvidia-driver-525 - distro non-free
driver   : nvidia-driver-525-server - distro non-free
driver   : nvidia-driver-515 - distro non-free
driver   : nvidia-driver-510 - distro non-free
driver   : nvidia-driver-530-open - distro non-free recommended
driver   : nvidia-driver-515-server - distro non-free
driver   : nvidia-driver-530 - distro non-free
driver   : nvidia-driver-525-open - distro non-free
driver   : nvidia-driver-470-server - distro non-free
driver   : nvidia-driver-470 - distro non-free
driver   : xserver-xorg-video-nouveau - distro free builtin

相关内容