ubuntu-drivers 安装 nvidia 驱动程序时出现“UnboundLocalError:局部变量‘version’在赋值前被引用”

ubuntu-drivers 安装 nvidia 驱动程序时出现“UnboundLocalError:局部变量‘version’在赋值前被引用”

在最新内核升级后,我在重新安装 nvidia 驱动程序时遇到了麻烦。通常,ubuntu-drivers 可以处理这个问题,但这次不行。

我已经这样做了sudo apt purge -y nvidia-*,这通常可以在重新安装时解决问题,但这没有帮助。

当我运行时ubuntu-drivers install,出现此错误:

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

底部的 with_nvidia_kms 消息是否与 DKMS 有关?在切换到 ubuntu-drivers 之前,我过去在使 dkms 工作时遇到过很多问题。

这一切都正常进行,直到最近的升级(涉及内核)为止。

答案1

这涉及到漏洞已经修复,应该通过升级软件包来解决ubuntu-drivers-common

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

否则,手动解决方案包括编辑/usr/lib/python3/dist-packages/UbuntuDrivers/detect.py“文件并将第 835 行替换为:

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

我唯一要做的改变是将 -1 改为 -2。否则它会在 try 块中引发 ValueError,并且不会为版本变量提供任何值。

答案2

有一个漏洞现已发布修复程序。您可以使用以下命令升级 Ubuntu 驱动程序包:

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

相关内容