{"id":5670,"library":"nvidia-ml-py","title":"NVIDIA Management Library Python Bindings","description":"nvidia-ml-py provides official Python bindings for the NVIDIA Management Library (NVML), enabling programmatic access to NVIDIA GPU monitoring and management functions. It wraps the NVML C shared library, which is typically distributed with NVIDIA graphics drivers. The library is actively maintained with frequent updates, as indicated by its high versioning scheme.","status":"active","version":"13.595.45","language":"en","source_language":"en","source_url":"https://pypi.org/project/nvidia-ml-py/","tags":["NVIDIA","GPU","NVML","monitoring","management"],"install":[{"cmd":"pip install nvidia-ml-py","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"nvidia-ml-py is a wrapper around the NVML C library, which is part of the NVIDIA Linux graphics driver. A compatible driver must be installed on the system.","package":"NVIDIA Driver (with NVML library)","optional":false},{"reason":"NVML relies on CUDA, and a correctly configured CUDA installation is often necessary for full functionality.","package":"CUDA Toolkit","optional":true}],"imports":[{"note":"The primary way to import all exposed NVML functions and constants is to import everything from the 'pynvml' module, which is the internal module name used by nvidia-ml-py.","symbol":"All NVML functions and constants","correct":"from pynvml import *"}],"quickstart":{"code":"from pynvml import *\n\ntry:\n    nvmlInit()\n    print(f\"Driver Version: {nvmlSystemGetDriverVersion()}\")\n    deviceCount = nvmlDeviceGetCount()\n    for i in range(deviceCount):\n        handle = nvmlDeviceGetHandleByIndex(i)\n        print(f\"Device {i}: {nvmlDeviceGetName(handle)}\")\n        # Example: Get memory info\n        info = nvmlDeviceGetMemoryInfo(handle)\n        print(f\"  Total Memory: {info.total / (1024**3):.2f} GB\")\n        print(f\"  Used Memory: {info.used / (1024**3):.2f} GB\")\n        print(f\"  Free Memory: {info.free / (1024**3):.2f} GB\")\nexcept NVMLError as error:\n    print(f\"NVML Error: {error}\")\nfinally:\n    try:\n        nvmlShutdown()\n    except NVMLError as error:\n        print(f\"NVML Shutdown Error: {error}\")","lang":"python","description":"This quickstart demonstrates how to initialize NVML, retrieve the NVIDIA driver version, enumerate available GPUs, and query basic information like device name and memory usage. It includes error handling for NVML specific errors and ensures NVML is shut down properly."},"warnings":[{"fix":"Refer to NVIDIA's NVML documentation for driver-specific API changes. Test thoroughly after driver/CUDA updates or library upgrades. Consider pinning specific `nvidia-ml-py` versions in your `requirements.txt`.","message":"The library often breaks backward compatibility without comprehensive changelogs. Changes to underlying NVML structures (e.g., `nvmlProcessInfo_t` with CUDA 11+) can cause `FunctionNotFound` errors or incorrect results with older NVIDIA drivers.","severity":"breaking","affected_versions":"All versions, particularly when upgrading drivers or CUDA toolkit."},{"fix":"Ensure NVIDIA drivers are up-to-date and compatible with your GPU. Verify CUDA toolkit installation. Check user permissions for GPU access. Restart Python kernel/script after making system changes. Consult NVIDIA's documentation for specific driver/NVML compatibility.","message":"NVML initialization errors (`NVMLError_V1_UNINITIALIZED` or similar) are common due to outdated/missing NVIDIA drivers, misconfigured CUDA, permission issues, or conflicting driver versions.","severity":"gotcha","affected_versions":"All versions."},{"fix":"Always `pip install nvidia-ml-py` for the official, actively maintained bindings. Use `from pynvml import *` for imports, as `pynvml` is the module name within the `nvidia-ml-py` package.","message":"There can be confusion between `nvidia-ml-py` (official bindings) and other community-maintained packages like `pynvml` (which is deprecating its own bindings in favor of `nvidia-ml-py`) or the deprecated `nvidia-ml-py3`.","severity":"gotcha","affected_versions":"All versions, especially for new users."},{"fix":"Manually inspect the `pynvml.py` source for affected constants if you encounter type-related errors. If possible, upgrade to a version where this is known to be resolved, or implement workarounds in your code.","message":"Some constants within `pynvml.py` (e.g., `NVML_P2P_CAPS_INDEX_READ`) may be incorrectly defined as tuples instead of integers due to extraneous commas, leading to unexpected behavior.","severity":"gotcha","affected_versions":"Versions 11.525.131, 12.555.43, and potentially others."},{"fix":"Consult the exact function signature in the NVIDIA NVML C documentation and compare it with the Python binding's behavior. If an inconsistency is found, you might need to adjust your function call or be aware of potential issues.","message":"Some specific function bindings, such as `nvmlDeviceGetGpcClkMinMaxVfOffset` and `nvmlDeviceGetMemClkMinMaxVfOffset`, may incorrectly expect more parameters than required by the underlying C function, leading to argument errors.","severity":"gotcha","affected_versions":"Potentially current and past versions."}],"env_vars":null,"last_verified":"2026-04-05T00:00:00.000Z","next_check":"2026-07-04T00:00:00.000Z"}