6
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Ubuntu22.04のUbuntu-drivers autoinstallでubuntu-drivers "UnboundLocalError: local variable 'version' referenced before assignment" when installing nvidia driversエラー

Posted at

新規導入したPCにUbuntu22.04を入れ、nvidia-smiを使用するためにUbuntu-driversでドライバをダウンロードしようとしたところ次のようなエラーが発生した。

$ ubuntu-drivers devices
~~ここに導入可能なドライバ一覧が表示
$ 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 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

こちらによるとpythonで書かれたインストーラーの"-"を区切る場所がおかしいためにこのエラーが出るらしい

解決法1

指定されたドライバーをaptでインストールする

sudo apt install nvidia-driver-<~~~>

解決法2

インストーラーを修正する

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

で該当ファイルを開き
version = int(package_name.split('-')[-1])
この部分を
version = int(package_name.split('-')[2])
に修正する。

すると

ubuntu-driver autoinstall

が実行できるようになる

6
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?