如何在 Ubuntu 22.04 LTS 中正确安装 NVIDIA RTX 驱动程序?

如何在 Ubuntu 22.04 LTS 中正确安装 NVIDIA RTX 驱动程序?

我买了一台配备 GPU RTX 3050 移动版的游戏笔记本电脑。由于我想用它进行机器学习和深度学习,所以我想确保我能正确访问它的显卡。

到目前为止,我已经尝试过:

ubuntu-drivers devices

进而 :

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

答案1

我也遇到了同样的问题。我的解决方案是编辑detect.py命令

sudo gedit /usr/lib/python3/dist-packages/UbuntuDrivers/detect.py

然后滚动到第 835 行。

将该行代码更改为

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

保存并关闭文件。您可能还需要重新启动。

显然,这是一个错误,因为有些驱动程序以单词而不是整数结尾。例如:driver-name-525-open。此代码调整采用 525 整数值。

相关内容