Registry / ai-ml / nvidia-ml-py3

nvidia-ml-py3

JSON →
library7.352.0pypypi✓ verified 22d ago

The `nvidia-ml-py3` library provides Python 3 compatible bindings to the NVIDIA Management Library (NVML), a C-based API for monitoring and managing NVIDIA GPUs. It allows Python applications to query GPU statistics, health, and other operational data. This specific package is an older port for Python 3 from the original `nvidia-ml-py` and is currently at version 7.352.0. The project's GitHub repository indicates it is archived and recommends migrating to the actively maintained `nvidia-ml-py` package.

pip install nvidia-ml-py3
INSTALL
IMPORT
SIG · NVIDIA-ML-PY3
N
nvidia-ml-py3
ai-mlpythonv7.352.0
Install
2.4s avg
Import
45ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v7.352.0 · 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.040s · 19.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.4s · import 0.050s · 20MB
17MB installed
● package 17MB
Code
Verified usage

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

pynvml
import pynvml
import nvidia_ml_py3
The package name on PyPI is `nvidia-ml-py3`, but the internal module to import is `pynvml`.

Initializes the NVML library, retrieves the system's NVIDIA driver version, iterates through detected GPUs to display their name, temperature, and memory usage, and then properly shuts down the NVML library. Includes error handling for common NVML issues.

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) name = pynvml.nvmlDeviceGetName(handle) temperature = pynvml.nvmlDeviceGetTemperature(handle, pynvml.NVML_TEMPERATURE_GPU) memory_info = pynvml.nvmlDeviceGetMemoryInfo(handle) print(f" Device {i}: {name.decode('utf-8') if isinstance(name, bytes) else name}") print(f" Temperature: {temperature}°C") print(f" Memory: {memory_info.used >> 20}MiB / {memory_info.total >> 20}MiB (Used/Total)") except pynvml.NVMLError as error: print(f"NVML Error: {error}") print("Common causes: Missing/outdated NVIDIA drivers, permission issues, or no GPUs found.") finally: try: pynvml.nvmlShutdown() except pynvml.NVMLError as error: print(f"NVML Shutdown Error: {error}")
Debug
Known issues
breakingThe `nvidia-ml-py3` package is officially deprecated and its GitHub repository is archived. Users are strongly advised to switch to the actively maintained `nvidia-ml-py` package (note the lack of '3' in the name) for continued support and updates.
fix
Migrate to `pip install nvidia-ml-py` and update imports accordingly (e.g., `from pynvml import *` will still work, but check for any API changes).
affects: All versions
gotchaNVML functionality critically depends on a correctly installed and up-to-date NVIDIA GPU driver. Issues like 'NVML not initialized' or 'NVMLError: Driver Not Loaded' typically indicate driver problems, missing driver files, or insufficient user permissions to access GPU devices.
fix
Ensure NVIDIA drivers are installed and compatible with your GPU and OS. Verify the GPU is recognized (e.g., `nvidia-smi` command-line tool). Grant necessary permissions if running as a restricted user. Reinstalling NVIDIA drivers or the NVML libraries might be necessary.
affects: All versions
gotchaIt is essential to call `pynvml.nvmlInit()` before any other NVML functions and `pynvml.nvmlShutdown()` when your application finishes. Failing to call `nvmlInit()` will result in `NVMLError: Uninitialized`, and not calling `nvmlShutdown()` can lead to resource leaks.
fix
Always wrap NVML calls within a `try...finally` block to ensure `nvmlInit()` and `nvmlShutdown()` are called reliably, as shown in the quickstart example.
affects: All versions
breakingThe underlying `nvidia-ml-py` (and thus `nvidia-ml-py3`) has historically introduced backward-incompatible API changes, particularly concerning data structures like `nvmlProcessInfo_t`. Newer versions might introduce fields (e.g., `gpuInstanceId`, `computeInstanceId`) that are incompatible with older NVIDIA drivers, causing crashes or incorrect data.
fix
Pin the library version (e.g., `nvidia-ml-py==X.Y.Z`) that is compatible with your specific NVIDIA driver version. Refer to the `nvidia-ml-py` release history for compatibility notes.
affects: >=11.450.129 (of the underlying NVML API/nvidia-ml-py)
gotchaSome constant definitions in `pynvml.py` (e.g., `NVML_P2P_CAPS_INDEX_READ`, `NVML_GRID_LICENSE_EXPIRY_` definitions) have been reported to contain extraneous commas, inadvertently turning them into tuples instead of integers. This can cause unexpected type errors if used directly.
fix
Inspect the `pynvml.py` source for the exact constant definition if encountering type errors. If present, manually extract the integer value from the tuple or switch to a fixed version of the `nvidia-ml-py` library if available.
affects: >=11.525.131 (of the underlying nvidia-ml-py)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pynvml'
The `nvidia-ml-py3` package, which provides the `pynvml` module, is either not installed in the active Python environment or the environment is not correctly configured.
fix
Ensure the package is installed using `pip install nvidia-ml-py3`. Verify that your Python environment is correctly activated and that `pynvml` is listed in `pip freeze`.
NVMLError_Uninitialized
The NVIDIA Management Library (NVML) failed to initialize, most commonly due to missing, outdated, or incompatible NVIDIA GPU drivers, or an incorrectly configured CUDA toolkit.
fix
Update your NVIDIA GPU drivers to the latest version, verify that the CUDA toolkit is correctly installed and compatible with your drivers, and check user permissions to ensure your script can access GPU resources. Restarting your system might also help.
NVML Shared Library Not Found
The underlying NVML shared library (e.g., `libnvidia-ml.so` on Linux or `nvml.dll` on Windows) cannot be located by the `nvidia-ml-py3` binding. This often indicates a problem with the NVIDIA driver installation or system library paths.
fix
Confirm that NVIDIA drivers are correctly installed and that the NVML library files are present in your system's standard library paths (e.g., `/usr/lib`, `/usr/lib64` on Linux, or `C:\Windows\System32` on Windows). Reinstalling the NVIDIA drivers is often the most effective solution.
AttributeError: module 'pynvml' has no attribute '_nvmlGetFunctionPointer'
This error typically occurs when an application or another library expects a different version of the NVML Python bindings (e.g., the newer `nvidia-ml-py` package) than what `nvidia-ml-py3` provides, or when multiple conflicting NVML bindings are installed.
fix
Uninstall all existing NVML Python bindings (`pip uninstall nvidia-ml-py3 nvidia-ml-py py3nvml`). Then, install only the actively maintained `nvidia-ml-py` package: `pip install nvidia-ml-py`.
Upgrade
Version history
7.352.0latest on PyPI · released Jun 3, 2017
Audit
Dependencies
NVIDIA GPU DriversrequiredThis library is a wrapper around the NVIDIA Management Library (NVML) C-based API, which requires properly installed and up-to-date NVIDIA GPU drivers to function.
NVIDIA CUDA ToolkitrequiredNVML relies on the CUDA toolkit; a misconfigured CUDA installation can lead to initialization failures.
Agent activity
26 hits · last 30 days
node
18
OpenAI (training)
2
Amazon
1
Resources