{"id":326,"library":"psutil","title":"psutil","description":"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.","status":"active","version":"8.0.0","language":"python","source_language":"en","source_url":"https://github.com/giampaolo/psutil","tags":["system monitoring","process management","cross-platform","Python library"],"install":[{"cmd":"pip install psutil","lang":"bash","label":"Install psutil"}],"dependencies":[{"reason":"psutil is a standalone library and does not have external dependencies.","package":"psutil"}],"imports":[{"note":"Ensure that psutil is installed in your environment to avoid ImportError.","symbol":"psutil","correct":"import psutil"}],"quickstart":{"code":"import psutil\n\n# Get CPU times\ncpu_times = psutil.cpu_times(percpu=False)\nprint(cpu_times)\n\n# List all processes\nfor proc in psutil.process_iter(['pid', 'name']):\n    print(proc.info)","lang":"python","description":"This script demonstrates how to retrieve CPU times and list all running processes using psutil."},"warnings":[{"fix":"Replace 'psutil.OSX' with 'psutil.MACOS' in your code.","message":"In version 8.0.0, the 'psutil.OSX' constant has been deprecated and replaced with 'psutil.MACOS'.","severity":"breaking","affected_versions":"8.0.0"},{"fix":"Install psutil using 'pip install psutil'.","message":"Ensure that psutil is installed in your environment to avoid ImportError.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-12T13:04:47.642Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Run `pip install psutil` in your terminal to install the library. If using a virtual environment, ensure it's activated.","cause":"The 'psutil' library is not installed in your Python environment or the Python interpreter being used cannot find it.","error":"ModuleNotFoundError: No module named 'psutil'"},{"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).","cause":"Your script lacks the necessary permissions to retrieve information for certain system processes or processes owned by other users.","error":"psutil.AccessDenied (pid=...)"},{"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.","cause":"The process with the specified PID terminated between the time its PID was obtained and when psutil attempted to gather its information.","error":"psutil.NoSuchProcess: process no longer exists (pid=...)"},{"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)`.","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.","error":"psutil.cpu_percent() always returns 0.0 (or Process.cpu_percent())"},{"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.","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`.","error":"AttributeError: module 'psutil' has no attribute 'some_attribute'"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":1.8,"disk_size":"18.5M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.8,"disk_size":"19M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.1,"mem_mb":2,"disk_size":"20.5M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.08,"mem_mb":2,"disk_size":"21M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.07,"mem_mb":2,"disk_size":"12.3M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.07,"mem_mb":2,"disk_size":"13M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.07,"mem_mb":2,"disk_size":"12.0M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.07,"mem_mb":1.8,"disk_size":"13M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":1.7,"disk_size":"18.0M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.7,"disk_size":"19M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}