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.
pip install pynvmlVerified import paths — ran on the pinned version, not inferred.
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.
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.
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.
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.
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.
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`).
Install the official NVIDIA bindings, which 'pynvml' now wraps: `pip install nvidia-ml-py`.
Ensure that the latest NVIDIA GPU drivers are installed and up to date, that a compatible NVIDIA GPU is present and recognized by the system, and that the user has sufficient permissions to access GPU resources. Restart the Python kernel or script after making changes.
Install or update the NVIDIA GPU drivers for your system. Verify GPU presence and driver status using the `nvidia-smi` command. If running in Docker, ensure the container is started with appropriate GPU access flags (e.g., `--gpus all`).
Update your NVIDIA GPU driver to the latest version to ensure it supports the NVML functions expected by `pynvml`. Alternatively, if a driver update is not possible, downgrade your `pynvml` or `nvidia-ml-py` package to a version compatible with your existing driver.