Source code for mendevi.testing.install

"""Test if the dependents libraries are well installed and linked.

Basicaly, it checks if the installation seems to be correct.
"""

import logging
import re
import subprocess

import av
import torch

VERSION_MIN = 6
VERSION_MAX = 8






[docs] def test_gpu_torch() -> None: """Test if torch is able to use the GPU.""" # possible to test lspci | grep ' NVIDIA ' if torch.cuda.is_available(): return # case always ok try: result = subprocess.run(["lshw", "-C", "display"], capture_output=True, check=True) except FileNotFoundError as err: try: subprocess.run(["nvidia-smi"], capture_output=True, check=True) except FileNotFoundError: return # assume there are not graphical card msg = ( "There seems to be an nvidia gpu on this machine, " "however torch is not able to use it, please reinstall cuda" ) raise ImportError(msg) from err if b" nvidia " in result.stdout.lower(): msg = ( "There seems to be an nvidia gpu on this machine, " "however torch is not able to use it, please reinstall cuda" ) raise ImportError(msg)