Code Execution Visualizer & Explainer - Generate step-by-step visual explanations of Python code execution.
- π― Step-by-step execution tracing - See exactly what happens at each line
- π Variable state visualization - Track how variables change over time
- πΌοΈ Export to images - Generate PNG diagrams for documentation
- π¬ Export to GIF/video - Create animated explanations for tutorials
- π¨ Beautiful terminal output - Rich console visualization
- π Memory diagrams - Visualize object references and data structures
- π Loop unwinding - See each iteration of loops clearly
- π Perfect for teaching - Create educational content effortlessly
pip install explainflowFor video export support:
pip install explainflow[video]For CLI support:
pip install explainflow[cli]Install everything:
pip install explainflow[all]If you encounter the error:
Fatal error in launcher: Unable to create process using '"C:\...\python.exe" "C:\...\pip.exe"'
Use this command instead:
python -m pip install explainflowWhy does this happen?
This is a known Windows pip launcher issue (not specific to explainflow) that occurs when:
- Python is installed in a path with spaces (e.g.,
C:\Program Files) - The pip.exe launcher has a stale or corrupted Python path reference
- Multiple Python versions are installed
Permanent fixes:
- Recommended: Always use
python -m pip install <package>on Windows - Repair pip:
python -m pip install --upgrade --force-reinstall pip - Use virtual environments: Create a venv in a path without spaces
- Reinstall Python: Install to a simple path like
C:\Python312
# Create virtual environment
python -m venv venv
# Activate (Windows PowerShell)
.\venv\Scripts\Activate.ps1
# Activate (Windows CMD)
.\venv\Scripts\activate.bat
# Activate (Linux/macOS)
source venv/bin/activate
# Install explainflow
pip install explainflowfrom explainflow import explain
# Explain a simple code snippet
code = '''
x = 5
y = 10
result = x + y
print(result)
'''
# Generate step-by-step explanation
explain(code)from explainflow import explain, export_image
code = '''
numbers = [1, 2, 3, 4, 5]
total = 0
for n in numbers:
total += n
print(total)
'''
# Generate and export as image
trace = explain(code, output="silent")
export_image(trace, "loop_explanation.png")from explainflow import explain, export_gif
code = '''
def factorial(n):
if n <= 1:
return 1
return n * factorial(n - 1)
result = factorial(5)
'''
trace = explain(code, output="silent")
export_gif(trace, "factorial.gif", fps=1)from explainflow import trace
@trace
def bubble_sort(arr):
n = len(arr)
for i in range(n):
for j in range(0, n-i-1):
if arr[j] > arr[j+1]:
arr[j], arr[j+1] = arr[j+1], arr[j]
return arr
# This will automatically trace and explain the execution
bubble_sort([64, 34, 25, 12, 22, 11, 90])# Explain a Python file
explainflow run mycode.py
# Export as image
explainflow run mycode.py --output explanation.png
# Export as GIF
explainflow run mycode.py --output explanation.gif --fps 2
# Watch mode - re-run on file changes
explainflow watch mycode.py- Understand how loops and recursion work
- Debug your code visually
- Study algorithm execution step-by-step
- Create visual explanations for lectures
- Generate diagrams for assignments
- Build interactive tutorials
- Add visual code explanations to docs
- Create GIFs for README files
- Generate step-by-step guides
- Trace variable changes
- Understand control flow
- Find logic errors visually
Execute and explain code step-by-step.
code: Python code string to explainoutput: Output mode - "rich" (terminal), "silent", "simple"max_steps: Maximum execution steps to trace- Returns:
ExecutionTraceobject
Export execution trace as a PNG image.
Export execution trace as an animated GIF.
Decorator to automatically trace function execution.
ExplainFlow supports multiple themes:
dark(default) - Dark background, easy on eyeslight- Light background for printingcolorblind- Accessible color scheme
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
If you see this error on Windows:
Fatal error in launcher: Unable to create process using '"..."'
Quick Fix - Use python -m pip instead of pip:
python -m pip install explainflowPermanent Fix - Repair your pip installation:
python -m pip install --upgrade --force-reinstall pipThis is a Windows-specific issue with the pip launcher, not a problem with explainflow. See pip issue discussion for more details.
Make sure you're using the same Python environment where you installed explainflow:
python -c "import explainflow; print(explainflow.__version__)"Install the video dependencies:
python -m pip install explainflow[video]- Inspired by Python Tutor
- Built with Rich for beautiful terminal output
- Uses Pillow for image generation
- Create an issue for bug reports or feature requests
- Star β the repo if you find it useful!
Made with β€οΈ for the Python community