psutil

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

psutil is a cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network, sensors) in Python. It is useful for system monitoring, profiling, limiting process resources, and managing running processes. The current version is 8.0.0, released on March 28, 2026, with a regular release cadence.

pip install psutil
error ModuleNotFoundError: No module named 'psutil'
cause The 'psutil' library is not installed in your Python environment or the Python interpreter being used cannot find it.
fix
Run pip install psutil in your terminal to install the library. If using a virtual environment, ensure it's activated.
error psutil.AccessDenied (pid=...)
cause Your script lacks the necessary permissions to retrieve information for certain system processes or processes owned by other users.
fix
Wrap the problematic psutil calls in a try-except psutil.AccessDenied: block to gracefully skip processes you don't have access to, or run the script with elevated privileges (e.g., sudo python your_script.py on Linux/macOS or 'Run as Administrator' on Windows).
error psutil.NoSuchProcess: process no longer exists (pid=...)
cause The process with the specified PID terminated between the time its PID was obtained and when psutil attempted to gather its information.
fix
Always enclose operations on psutil.Process objects, especially when iterating through processes, within a try-except psutil.NoSuchProcess: block to handle cases where a process disappears.
error psutil.cpu_percent() always returns 0.0 (or Process.cpu_percent())
cause The `cpu_percent()` function (both system-wide and per-process) calculates CPU utilization based on the difference between two calls. The first call provides a baseline and will always return 0.0.
fix
Call psutil.cpu_percent() (or Process.cpu_percent()) twice with a short time interval (e.g., 0.1 to 1 second) in between. Discard the result of the first call as it's a meaningless baseline. Example: psutil.cpu_percent(interval=None) then time.sleep(0.1) then psutil.cpu_percent(interval=None).
error AttributeError: module 'psutil' has no attribute 'some_attribute'
cause You are attempting to access a function or attribute that does not exist in the installed version of psutil, or your script might be shadowed by a local file named `psutil.py`.
fix
Ensure psutil is updated to the latest version (pip install --upgrade psutil) and verify the attribute/method name against the official psutil documentation. Also, check if there's any file named psutil.py in your project directory that might be conflicting with the installed library.
breaking In version 8.0.0, the 'psutil.OSX' constant has been deprecated and replaced with 'psutil.MACOS'.
fix Replace 'psutil.OSX' with 'psutil.MACOS' in your code.
gotcha Ensure that psutil is installed in your environment to avoid ImportError.
fix Install psutil using 'pip install psutil'.
python os / libc status wheel install import disk
3.10 alpine (musl) - - 0.04s 18.5M
3.10 slim (glibc) - - 0.03s 19M
3.11 alpine (musl) - - 0.10s 20.5M
3.11 slim (glibc) - - 0.08s 21M
3.12 alpine (musl) - - 0.07s 12.3M
3.12 slim (glibc) - - 0.07s 13M
3.13 alpine (musl) - - 0.07s 12.0M
3.13 slim (glibc) - - 0.07s 13M
3.9 alpine (musl) - - 0.04s 18.0M
3.9 slim (glibc) - - 0.03s 19M

This script demonstrates how to retrieve CPU times and list all running processes using psutil.

import psutil

# Get CPU times
cpu_times = psutil.cpu_times(percpu=False)
print(cpu_times)

# List all processes
for proc in psutil.process_iter(['pid', 'name']):
    print(proc.info)