{"id":6868,"library":"scalene","title":"Scalene: CPU, GPU, and Memory Profiler","description":"Scalene is a high-resolution, low-overhead profiler for Python that analyzes CPU, GPU, and memory usage, providing AI-powered optimization suggestions. It's actively developed with frequent releases, typically addressing bug fixes, performance improvements, and compatibility updates for various Python versions and ecosystems.","status":"active","version":"2.2.1","language":"python","source_language":"en","source_url":"https://github.com/plasma-umass/scalene","tags":["profiler","performance","cpu","gpu","memory","ai","optimization"],"install":[{"cmd":"pip install scalene","lang":"bash","label":"Install Scalene"}],"dependencies":[],"imports":[{"note":"For programmatic control (start/stop) of the profiler. Most users will use the CLI directly.","symbol":"scalene_profiler","correct":"from scalene import scalene_profiler"}],"quickstart":{"code":"# my_script.py\nimport time\nimport math\n\ndef calculate_heavy_stuff(n):\n    result = 0\n    for _ in range(n):\n        result += math.sin(math.sqrt(time.time()))\n    return result\n\ndef main():\n    print(\"Starting heavy calculations...\")\n    calculate_heavy_stuff(1000000) # Perform 1 million iterations\n    print(\"Calculations finished.\")\n\nif __name__ == \"__main__\":\n    main()\n\n# To run the profiler from your terminal:\n# python -m scalene my_script.py","lang":"python","description":"Create a Python script (e.g., `my_script.py`) and then run Scalene from the command line using `python -m scalene my_script.py`. Scalene will generate a detailed profile in your terminal or an HTML report."},"warnings":[{"fix":"Ensure your Python environment is not 3.11.0. Upgrade to 3.11.1+ or use another compatible version (3.8, 3.9, 3.10, 3.12, etc.).","message":"Scalene explicitly requires Python versions `!=3.11.0` and `>=3.8`. This means Python 3.11.0 is not supported, though 3.11.1+ should be fine.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade to Scalene v2.2.1 or newer. This version includes a fix that handles conflicts by falling back to alternative tool IDs or the legacy `PyEval_SetTrace` tracer.","message":"Earlier versions of Scalene (before 2.2.1) could crash with `SIGSEGV` when used with PyTorch Lightning on Python 3.12+ due to `sys.monitoring` tool ID conflicts.","severity":"breaking","affected_versions":"<2.2.1"},{"fix":"Upgrade to Scalene v2.2.1 or newer to ensure compatibility with TensorFlow 2.21 and later.","message":"TensorFlow 2.21+ changed `trace.enabled` from a callable to a boolean, causing compatibility issues with Scalene versions prior to 2.2.1.","severity":"breaking","affected_versions":"<2.2.1"},{"fix":"Upgrade to Scalene v2.1.2 or newer to resolve this issue. Version 2.1.2 fixed the Windows timer loop to use the actual configured sampling rate.","message":"On Windows, Scalene v2.1.x could experience extreme slowness and memory explosion during CPU profiling due to a hardcoded 1ms sampling interval, overriding the configured rate.","severity":"gotcha","affected_versions":"2.1.0 - 2.1.1"},{"fix":"For general profiling, always prefer `python -m scalene <your_script.py> [args]` or use the Jupyter `%%scalene` magic. Use the programmatic API (`from scalene import scalene_profiler; scalene_profiler.start()`) for fine-grained control within specific code blocks.","message":"The primary and recommended way to use Scalene for profiling is via the command-line interface (`python -m scalene your_script.py`) or Jupyter magics (`%%scalene`). While a programmatic API exists, directly importing and calling functions to *run* the profiler in a general context is less common and might not capture the full execution scope as effectively.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'activ':34 'address':40 'ai':28,59 'ai-pow':27 'analyz':20 'bug':41 'compat':46 'cpu':2,21,56 'develop':35 'ecosystem':53 'fix':42 'frequent':37 'gpu':3,22,57 'high':11 'high-resolut':10 'improv':44 'low':14 'low-overhead':13 'memori':5,24,58 'optim':30,60 'overhead':15 'perform':43,55 'power':29 'profil':6,16,54 'provid':26 'python':18,50 'releas':38 'resolut':12 'scalen':1,7 'suggest':31 'typic':39 'updat':47 'usag':25 'various':49 'version':51","created_at":"2026-04-15T18:46:28.597405+00:00","updated_at":"2026-04-16T21:22:40.406637+00:00","problems":[{"fix":"If not installed, run `pip install scalene`. If already installed, verify your PATH includes the directory where pip installs executables (e.g., `~/.local/bin` on Linux/macOS or the `Scripts` folder in a virtual environment).","cause":"The `scalene` executable is not located in any directory listed in your system's PATH environment variable, or it was not installed correctly.","error":"scalene: command not found"},{"fix":"Install Scalene using `pip install scalene` in the Python environment you intend to use.","cause":"The `scalene` Python package is not installed in the currently active Python environment, or the environment from which you are trying to import it.","error":"ModuleNotFoundError: No module named 'scalene'"},{"fix":"Install the appropriate Python development headers for your system. For Debian/Ubuntu: `sudo apt-get install python3-dev`. For Fedora: `sudo dnf install python3-devel`. On macOS, ensure Xcode command line tools are installed (`xcode-select --install`).","cause":"Scalene requires Python development headers (like `Python.h`) to compile its C extensions, and these headers are missing on your system.","error":"fatal error: Python.h: No such file or directory"},{"fix":"Try upgrading Scalene to the latest version (`pip install --upgrade scalene`), ensure your Python version is officially supported, or test it in a clean virtual environment. If the issue persists, report it to the Scalene developers with detailed system information.","cause":"A critical low-level memory error, often stemming from an incompatibility with the Python version, specific system configurations, or a bug within Scalene's C extensions.","error":"Segmentation fault (core dumped)"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"2.3.0","cli_name":"scalene","cli_version":"Scalene version 2.3.0 (2026.05.08)","type":"library","homepage":"https://plasma-umass.org/scalene/","github":"https://github.com/plasma-umass/scalene","docs":null,"changelog":null,"pypi":"https://pypi.org/project/scalene/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops","observability","ai-ml"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}