当我输入 nvidia-detector 时,出现了 ValueError: invalid literal for int() with base 10: 'server'

当我输入 nvidia-detector 时,出现了 ValueError: invalid literal for int() with base 10: 'server'
ubuntu@deeplearn-ubuntu:~$ nvidia-detector 
Traceback (most recent call last):
  File "/bin/nvidia-detector", line 8, in <module>
    a = NvidiaDetection(printonly=True, verbose=False)
  File "/usr/lib/python3/dist-packages/NvidiaDetector/nvidiadetector.py", line 73, in __init__
    self.getData()
  File "/usr/lib/python3/dist-packages/NvidiaDetector/nvidiadetector.py", line 163, in getData
    driver_version = self.__get_value_from_name(stripped_package_name)
  File "/usr/lib/python3/dist-packages/NvidiaDetector/nvidiadetector.py", line 92, in __get_value_from_name
    v = int(name)
ValueError: invalid literal for int() with base 10: 'server'

答案1

解决方法是在 /usr/lib/python3/dist-packages/NvidiaDetector/nvidiadetector.py 中添加以下行:

--- nvidiadetector.py   2020-08-09 15:54:01.089855652 +0400
+++ /usr/lib/python3/dist-packages/NvidiaDetector/nvidiadetector.py 2020-08-09 16:26:15.321390371 +0400
@@ -160,6 +160,8 @@
             # package names can be like "nvidia-173:i386" and we need to
             # extract the driver flavour from the name e.g. "173"
             stripped_package_name = package.name.split('-')[-1].split(':', 1)[0]
+            if not stripped_package_name.isnumeric():
+                stripped_package_name = package.name.split('-')[-2].split('-', -1)[0]
             driver_version = self.__get_value_from_name(stripped_package_name)
 
             try:

因为其中一个包在版本号后使用了字符串后缀。

相关内容