Registry / ai-ml / pynvml

pynvml

JSON →
library13.0.1pypypi✓ verified 26d ago

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 pynvml
INSTALL
IMPORT
SIG · PYNVML
P
pynvml
ai-mlpythonv13.0.1
Install
1.7s avg
Import
127ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v13.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.136s · 18.6MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.7s · import 0.118s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pynvml
import pynvml
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.

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.

import pynvml try: pynvml.nvmlInit() print(f"Driver Version: {pynvml.nvmlSystemGetDriverVersion()}") device_count = pynvml.nvmlDeviceGetCount() print(f"Found {device_count} GPU device(s).") for i in range(device_count): handle = pynvml.nvmlDeviceGetHandleByIndex(i) device_name = pynvml.nvmlDeviceGetName(handle) memory_info = pynvml.nvmlDeviceGetMemoryInfo(handle) temperature = pynvml.nvmlDeviceGetTemperature(handle, pynvml.NVML_TEMPERATURE_GPU) print(f"\nDevice {i} ({device_name.decode('utf-8')}):") print(f" Total Memory: {memory_info.total / (1024**3):.2f} GB") print(f" Used Memory: {memory_info.used / (1024**3):.2f} GB") print(f" Free Memory: {memory_info.free / (1024**3):.2f} GB") print(f" GPU Temperature: {temperature}°C") except pynvml.NVMLError as error: print(f"NVML Error: {error}") except Exception as e: print(f"An unexpected error occurred: {e}") finally: try: pynvml.nvmlShutdown() except pynvml.NVMLError_Uninitialized: pass # NVML was not initialized or already shut down
Debug
Known issues
breakingThe `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.
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.
affects: >=13.0.1
gotchaThe 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.
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.
affects: all
gotchaThe `nvidia-ml-py` library (which `pynvml` now wraps) has a history of breaking backward compatibility with often uncomprehensive changelogs, making migrations challenging.
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.
affects: all
gotchaMany 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.
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.
affects: all
gotchaNVML functions in `pynvml` do not return error codes directly but instead raise Python exceptions (specifically `pynvml.NVMLError` and its subclasses) for failures.
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`).
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pynvml'
The 'pynvml' package or its underlying dependency 'nvidia-ml-py' is not installed in the active Python environment.
fix
Install the official NVIDIA bindings, which 'pynvml' now wraps: `pip install nvidia-ml-py`.
pynvml.nvml.NVMLError_Uninitialized: Uninitialized
The NVIDIA Management Library (NVML) could not be initialized, often due to outdated or missing NVIDIA drivers, incorrect CUDA toolkit installation, permission issues, or the absence of a detected NVIDIA GPU.
fix
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.
pynvml.nvml.NVMLError_DriverNotLoaded: Driver Not Loaded
This error specifically indicates that the NVIDIA GPU driver is not loaded or properly installed, or that the system does not have an NVIDIA GPU. This is common in environments like Docker where GPU access might not be configured.
fix
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`).
AttributeError: module 'pynvml' has no attribute 'nvmlDeviceGetCudaComputeCapability' (or similar 'nvmlDeviceGet...' function)
This occurs when the installed version of `pynvml` (or the underlying `nvidia-ml-py`) attempts to call an NVML function that is not supported by the currently installed NVIDIA GPU driver, often because the driver is older than the library expects.
fix
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.
Upgrade
Version history
13.0.1latest on PyPI · released Sep 5, 2025
Audit
Dependencies
nvidia-ml-pyrequiredAs of pynvml version 12.0.0 and later, pynvml depends on and wraps nvidia-ml-py for the core NVML bindings.
Agent activity
20 hits · last 30 days
node
16
OpenAI (training)
1
Resources
pynvml — pip install pynvml · libregistry