py-cpuinfo

raw JSON →
9.0.0 verified Tue May 12 auth: no python install: verified

Py-cpuinfo is a pure Python library designed to retrieve detailed CPU information across various operating systems, including Linux, macOS, Windows, BSD, Solaris, Cygwin, Haiku, and BeagleBone. It functions without requiring any external programs or compilation beyond the standard OS provisions. The library is compatible with Python 3. The current stable version is 9.0.0, released in October 2022.

pip install py-cpuinfo
error ModuleNotFoundError: No module named 'cpuinfo'
cause The Python package is installed as `py-cpuinfo`, but developers often mistakenly try to import it using `import py-cpuinfo` or when it's not correctly bundled with freezing tools like PyInstaller.
fix
The correct way to import the library after installing py-cpuinfo is import cpuinfo.
error KeyError: 'brand'
cause The `get_cpu_info()` function returns a dictionary, and the 'brand' key might not always be present or directly available on certain CPU architectures (e.g., ARM-based systems like Raspberry Pi) or with older versions of the library, leading to a KeyError when attempting to access it directly.
fix
Safely access the dictionary key using the .get() method, for example: cpuinfo.get_cpu_info().get('brand'), which will return None if the key is not found instead of raising a KeyError.
error py-cpuinfo module not working correctly when compiling using pyinstaller or Cx_freeze
cause When `py-cpuinfo` is bundled into an executable using PyInstaller or Cx_freeze, it can sometimes cause issues like high CPU usage or multiple processes spawning due to how the library interacts with the process environment during freezing.
fix
If your application uses multiprocessing and is frozen into an executable, add from multiprocessing import freeze_support; if __name__ == '__main__': freeze_support() at the very beginning of your main script file.
error ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. inference-sdk 0.9.23 requires py-cpuinfo>=9.0.0, but you have py-cpuinfo 3.3.0 which is incompatible.
cause This error occurs when a project or another installed package has a dependency on a specific version range of `py-cpuinfo` (e.g., `>=9.0.0`), but an incompatible version is currently installed, or a conflicting requirement forces an older version.
fix
Try to upgrade py-cpuinfo to meet the dependency requirements using pip install --upgrade py-cpuinfo or explicitly install the required version: pip install py-cpuinfo>=9.0.0. If conflicts persist, consider creating a virtual environment or resolving broader dependency issues among your installed packages.
gotcha When compiling applications using PyInstaller or Cx_Freeze that incorporate `py-cpuinfo`, the frozen executable may exhibit high CPU usage or create multiple processes, potentially leading to crashes. This is a common issue with libraries that use multiprocessing.
fix Add `multiprocessing.freeze_support()` at the very beginning of your main script (before any other code) or ensure it's called if your freezing tool has a specific entry point for multiprocessing initialization. Refer to the `py-cpuinfo` GitHub issues or `multiprocessing` documentation for detailed integration with freezing tools.
gotcha The `py-cpuinfo` library provides 'Raw Fields' which are direct outputs from underlying system calls or CPUID registers. These values are unverified and may contain unexpected, incorrect, or even garbage data. Relying on these raw fields directly can lead to inaccurate information.
fix Always prefer the parsed and standardized fields provided by `get_cpu_info()` for reliable data. Use 'Raw Fields' with extreme caution and implement robust validation if absolutely necessary.
gotcha On some systems, the `hz_actual` and `hz_advertised` fields returned by `get_cpu_info()` may incorrectly report a static low frequency (e.g., 400MHz) instead of the CPU's actual or advertised maximum clock rates. This can lead to misleading performance metrics.
fix Be aware that these specific frequency fields might not always be accurate. If precise clock speed measurement is critical, consider cross-referencing with other system tools or exploring alternative hardware-specific methods outside of this library.
python os / libc status wheel install import disk
3.10 alpine (musl) wheel - 0.05s 17.9M
3.10 alpine (musl) - - 0.06s 17.9M
3.10 slim (glibc) wheel 1.5s 0.04s 18M
3.10 slim (glibc) - - 0.05s 18M
3.11 alpine (musl) wheel - 0.08s 19.8M
3.11 alpine (musl) - - 0.09s 19.8M
3.11 slim (glibc) wheel 1.7s 0.08s 20M
3.11 slim (glibc) - - 0.08s 20M
3.12 alpine (musl) wheel - 0.07s 11.7M
3.12 alpine (musl) - - 0.07s 11.7M
3.12 slim (glibc) wheel 1.5s 0.07s 12M
3.12 slim (glibc) - - 0.07s 12M
3.13 alpine (musl) wheel - 0.06s 11.4M
3.13 alpine (musl) - - 0.07s 11.3M
3.13 slim (glibc) wheel 1.4s 0.08s 12M
3.13 slim (glibc) - - 0.08s 12M
3.9 alpine (musl) wheel - 0.06s 17.4M
3.9 alpine (musl) - - 0.06s 17.4M
3.9 slim (glibc) wheel 1.7s 0.05s 18M
3.9 slim (glibc) - - 0.06s 18M

This example demonstrates how to retrieve and print all available CPU information using the `get_cpu_info()` function.

from cpuinfo import get_cpu_info

info = get_cpu_info()
for key, value in info.items():
    print(f"{key}: {value}")