{"id":2225,"library":"pynvml","title":"Python Utilities for the NVIDIA Management Library","description":"pynvml is a Python library that provides utilities for the NVIDIA Management Library (NVML). As of version 13.0.1, this project (gpuopenanalytics/pynvml) itself is deprecated, primarily serving as a wrapper that pins to the official `nvidia-ml-py` bindings. It offers a Python interface for GPU management and monitoring functions, with the core NVML functionality now sourced from `nvidia-ml-py`. The current version is 13.0.1, and the project indicates an inactive development status.","status":"deprecated","version":"13.0.1","language":"en","source_language":"en","source_url":"https://github.com/gpuopenanalytics/pynvml","tags":["gpu","nvidia","nvml","monitoring","system-management","hardware"],"install":[{"cmd":"pip install pynvml","lang":"bash","label":"Install latest pynvml"}],"dependencies":[{"reason":"As of pynvml version 12.0.0 and later, pynvml depends on and wraps nvidia-ml-py for the core NVML bindings.","package":"nvidia-ml-py"}],"imports":[{"note":"Even though the `pynvml` project is deprecated, the installed `pynvml` package (which wraps `nvidia-ml-py`) still provides the NVML bindings via the `pynvml` module.","symbol":"pynvml","correct":"import pynvml"}],"quickstart":{"code":"import pynvml\n\ntry:\n    pynvml.nvmlInit()\n    print(f\"Driver Version: {pynvml.nvmlSystemGetDriverVersion()}\")\n\n    device_count = pynvml.nvmlDeviceGetCount()\n    print(f\"Found {device_count} GPU device(s).\")\n\n    for i in range(device_count):\n        handle = pynvml.nvmlDeviceGetHandleByIndex(i)\n        device_name = pynvml.nvmlDeviceGetName(handle)\n        memory_info = pynvml.nvmlDeviceGetMemoryInfo(handle)\n        temperature = pynvml.nvmlDeviceGetTemperature(handle, pynvml.NVML_TEMPERATURE_GPU)\n\n        print(f\"\\nDevice {i} ({device_name.decode('utf-8')}):\")\n        print(f\"  Total Memory: {memory_info.total / (1024**3):.2f} GB\")\n        print(f\"  Used Memory: {memory_info.used / (1024**3):.2f} GB\")\n        print(f\"  Free Memory: {memory_info.free / (1024**3):.2f} GB\")\n        print(f\"  GPU Temperature: {temperature}°C\")\n\nexcept pynvml.NVMLError as error:\n    print(f\"NVML Error: {error}\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")\nfinally:\n    try:\n        pynvml.nvmlShutdown()\n    except pynvml.NVMLError_Uninitialized:\n        pass # NVML was not initialized or already shut down\n","lang":"python","description":"This quickstart demonstrates how to initialize NVML, query the number of available GPUs, retrieve device-specific information (name, memory, temperature), and properly shut down the NVML library. Error handling for common NVML issues is included."},"warnings":[{"fix":"Migrate your project to install and use `nvidia-ml-py` directly. While `pynvml` currently wraps `nvidia-ml-py`, relying on the deprecated wrapper is not recommended for long-term projects.","message":"The `pynvml` project (gpuopenanalytics/pynvml) and its `pynvml_utils` module are officially deprecated as of version 13.0.1. Users are strongly advised to transition to using the `nvidia-ml-py` package directly for future development and stability.","severity":"breaking","affected_versions":">=13.0.1"},{"fix":"Always wrap your NVML operations within a `try...finally` block to ensure `pynvml.nvmlShutdown()` is called, even if errors occur. Check for `NVMLError_Uninitialized` on shutdown if `nvmlInit()` might have failed.","message":"The NVIDIA Management Library (NVML) must be explicitly initialized with `pynvml.nvmlInit()` and shut down with `pynvml.nvmlShutdown()`. Failing to call `nvmlShutdown()` can lead to resource leaks and prevent subsequent NVML operations.","severity":"gotcha","affected_versions":"all"},{"fix":"Pin your `nvidia-ml-py` dependency to a specific minor version in your `requirements.txt` or `pyproject.toml` to avoid unexpected breaking changes with new releases. Thoroughly test updates before deploying to production.","message":"The `nvidia-ml-py` library (which `pynvml` now wraps) has a history of breaking backward compatibility with often uncomprehensive changelogs, making migrations challenging.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure your application or script has the necessary system permissions to access NVML features. Consult NVIDIA's NVML documentation for specific privilege requirements for each function. Implement robust error handling (e.g., `try...except pynvml.NVMLError_NotPermitted`) to gracefully manage permission issues.","message":"Many NVML functions require elevated privileges (e.g., admin/root) to query certain GPU performance counters or to modify GPU settings. Running without sufficient permissions can result in `NVMLError` exceptions.","severity":"gotcha","affected_versions":"all"},{"fix":"Wrap calls to `pynvml` functions in `try...except pynvml.NVMLError as error:` blocks to catch and handle errors appropriately. Check the specific `NVMLError` subclass for detailed error information (e.g., `NVMLError_DriverNotLoaded`, `NVMLError_Uninitialized`).","message":"NVML functions in `pynvml` do not return error codes directly but instead raise Python exceptions (specifically `pynvml.NVMLError` and its subclasses) for failures.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}