{"library":"py3nvml","title":"Python 3 Bindings for NVIDIA Management Library (NVML)","description":"py3nvml provides Python 3 bindings for the NVIDIA Management Library (NVML), allowing users to monitor and manage NVIDIA GPUs. It's built on the original pynvml project but specifically targets Python 3. The current version is 0.2.7, and releases are infrequent, primarily for maintenance or compatibility updates.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install py3nvml"],"cli":null},"imports":["from pynvml import nvmlInit","from pynvml import NVMLError"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"from pynvml import nvmlInit, nvmlShutdown, nvmlDeviceGetCount, nvmlDeviceGetHandleByIndex, nvmlDeviceGetName, nvmlDeviceGetMemoryInfo, NVMLError\n\ntry:\n    nvmlInit()\n    device_count = nvmlDeviceGetCount()\n    print(f\"Found {device_count} NVIDIA GPU(s).\")\n\n    for i in range(device_count):\n        handle = nvmlDeviceGetHandleByIndex(i)\n        name = nvmlDeviceGetName(handle)\n        mem_info = nvmlDeviceGetMemoryInfo(handle)\n        print(f\"  Device {i}: {name} - Total Memory: {mem_info.total / (1024**3):.2f} GB, Used: {mem_info.used / (1024**3):.2f} GB\")\n\nexcept NVMLError as error:\n    print(f\"NVMLError: {error}\")\n    if error.value == 6: # NVML_ERROR_DRIVER_NOT_LOADED\n        print(\"\\n  Cause: NVIDIA drivers may not be installed or are outdated, or the NVML library cannot be found.\")\n        print(\"  Fix: Ensure NVIDIA display drivers are properly installed and the NVML shared library is accessible.\")\n    elif error.value == 10: # NVML_ERROR_NO_PERMISSION\n        print(\"\\n  Cause: Insufficient permissions to access NVIDIA GPU devices.\")\n        print(\"  Fix: Run the script with appropriate permissions (e.g., as root or with specific user group).\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")\nfinally:\n    try:\n        nvmlShutdown()\n        print(\"NVML shutdown successfully.\")\n    except NVMLError as error:\n        print(f\"Error during NVML shutdown: {error}\")","lang":"python","description":"This quickstart initializes NVML, queries the number of available NVIDIA GPUs, iterates through them to print their name and memory usage, and finally shuts down NVML. It includes basic error handling for common NVML issues.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}