Registry / ai-ml / py3nvml

py3nvml

JSON →
library0.2.7pypypi✓ verified 85d ago

py3nvml provides Python 3 bindings for the NVIDIA Management Library (NVML), allowing users to monitor and manage NVIDIA GPUs. It's built on the original pynvml project but specifically targets Python 3. The current version is 0.2.7, and releases are infrequent, primarily for maintenance or compatibility updates.

pip install py3nvml
INSTALL
IMPORT
SIG · PY3NVML
P
py3nvml
ai-mlpythonv0.2.7
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.2.7 · 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.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18.4MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.6s · import 0.000s · 19MB
16MB installed
● package 16MB
Code
Verified usage

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

get_free_gpus
from py3nvml import get_free_gpus
from pynvml import nvmlInit
grab_gpus
from py3nvml import grab_gpus
from pynvml import nvmlInit
nvidia_smi
from py3nvml import nvidia_smi
from pynvml import nvmlInit

This quickstart initializes NVML, queries the number of available NVIDIA GPUs, iterates through them to print their name and memory usage, and finally shuts down NVML. It includes basic error handling for common NVML issues.

from pynvml import nvmlInit, nvmlShutdown, nvmlDeviceGetCount, nvmlDeviceGetHandleByIndex, nvmlDeviceGetName, nvmlDeviceGetMemoryInfo, NVMLError try: nvmlInit() device_count = nvmlDeviceGetCount() print(f"Found {device_count} NVIDIA GPU(s).") for i in range(device_count): handle = nvmlDeviceGetHandleByIndex(i) name = nvmlDeviceGetName(handle) mem_info = nvmlDeviceGetMemoryInfo(handle) print(f" Device {i}: {name} - Total Memory: {mem_info.total / (1024**3):.2f} GB, Used: {mem_info.used / (1024**3):.2f} GB") except NVMLError as error: print(f"NVMLError: {error}") if error.value == 6: # NVML_ERROR_DRIVER_NOT_LOADED print("\n Cause: NVIDIA drivers may not be installed or are outdated, or the NVML library cannot be found.") print(" Fix: Ensure NVIDIA display drivers are properly installed and the NVML shared library is accessible.") elif error.value == 10: # NVML_ERROR_NO_PERMISSION print("\n Cause: Insufficient permissions to access NVIDIA GPU devices.") print(" Fix: Run the script with appropriate permissions (e.g., as root or with specific user group).") except Exception as e: print(f"An unexpected error occurred: {e}") finally: try: nvmlShutdown() print("NVML shutdown successfully.") except NVMLError as error: print(f"Error during NVML shutdown: {error}")
Debug
Known issues
gotchapy3nvml is a Python wrapper for the NVIDIA Management Library (NVML) C library. It requires NVIDIA drivers and the underlying NVML library to be correctly installed and accessible on your system. Without these, the Python library will raise errors such as `NVMLError_DriverNotLoaded` or `NVMLError_LibraryNotFound`.
fix
Ensure you have up-to-date NVIDIA display drivers installed on your system. On Linux, ensure `libnvidia-ml.so` is in your `LD_LIBRARY_PATH`. On Windows, ensure `nvml.dll` is discoverable via your system's PATH.
affects: All versions
gotchaDespite the package name `py3nvml`, the core NVML functions and exceptions are exposed through the `pynvml` namespace. Users often try to import directly from `py3nvml` (e.g., `from py3nvml import nvmlInit`), which will result in `NameError`.
fix
Always import NVML functions and exceptions from `pynvml`, like `from pynvml import nvmlInit, NVMLError`.
affects: All versions
gotchaNVML initialization (`nvmlInit()`) and shutdown (`nvmlShutdown()`) are crucial. Forgetting to call `nvmlShutdown()` can lead to resource leaks or unexpected behavior in long-running applications, although modern Python interpreters and OS often clean up on exit.
fix
Always call `nvmlInit()` before making any other NVML calls and `nvmlShutdown()` when you are finished, ideally within a `try...finally` block to ensure shutdown even if errors occur.
affects: All versions
Upgrade
Version history
0.2.7latest on PyPI · released Nov 22, 2021
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
py3nvml — pip install py3nvml · libregistry