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-py3Verified import paths — ran on the pinned version, not inferred.
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.
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).
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.
Always wrap NVML calls within a `try...finally` block to ensure `nvmlInit()` and `nvmlShutdown()` are called reliably, as shown in the quickstart example.
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.
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.
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`.
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.
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.
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`.