- 1 year ago
Get current frequency in python with psutil (Windows)
To get the current CPU frequency in Python using the psutil
library on Windows, you can follow these steps:
Install
psutil
: If you haven't installed thepsutil
library, you can install it usingpip
by running the following command in your command prompt or terminal:pip install psutil
Import the
psutil
module: In your Python script, import thepsutil
module by adding the following line at the top:pythonimport psutil
Get the current CPU frequency: Use the
psutil.cpu_freq()
function to retrieve the current CPU frequency. This function returns a named tuple with thecurrent
attribute representing the current frequency in MHz. Here's an example of how to use it:pythonimport psutil
cpu_freq = psutil.cpu_freq().current
print(f"Current CPU Frequency: {cpu_freq} MHz")
This will print the current CPU frequency in MHz.
The psutil
library provides many other useful functions to gather system information, including CPU utilization, memory usage, disk usage, and more. Refer to the psutil
documentation for more details on its capabilities.
Please note that the psutil
library provides cross-platform support, so the same code should work on Windows, Linux, and macOS.