Windows Terminal Encoding
Fix UnicodeEncodeError on Windows CMD/PowerShell and get full Rich output
On Windows, PraisonAI automatically reconfigures sys.stdout / sys.stderr of the Typer process to UTF-8 before any command runs, and falls back to ASCII glyphs for any output path that still needs it — Rich-heavy commands like praisonai browser doctor work without $env:PYTHONIOENCODING='utf-8'.
from praisonaiagents import Agent
agent = Agent(name="windows-agent", instructions="Handle Unicode output on Windows terminals.")
agent.start("Display this response with proper Unicode encoding on Windows.")The user sends Unicode text; PraisonAI renders safely without crashing legacy Windows consoles.
Detection Flow
Two-Layer Mitigation
Every Typer command passes through two layers on Windows, so Unicode output never crashes the CLI.
What Runs on Every Typer Invocation
| Step | Function | Scope | Effect |
|---|---|---|---|
| 1 | os.environ['PYTHONIOENCODING'] = 'utf-8' | Child processes | Subprocesses PraisonAI spawns inherit UTF-8 stdio (only set when a legacy code page is detected and the variable is not already set). |
| 2 | _ensure_utf8_stdio() | Current process | Reconfigures sys.stdout / sys.stderr to utf-8 with errors="replace". |
_ensure_utf8_stdio() behaviour:
| Situation | Result |
|---|---|
Stream already utf-8 or cp65001 | Left untouched |
Stream has no reconfigure method (redirected files, custom wrappers) | Skipped silently |
| Character that cannot be encoded | Written as ? instead of raising |
| macOS / Linux | Never called |
| Code page | Windows name | Before | After |
|---|---|---|---|
| 1252 | Western European | Fail | Pass |
| 437 | OEM US | Fail | Pass |
| 28591 | ISO Latin-1 | Fail | Pass |
| 65001 | UTF-8 | Pass | Pass |
Quick Start
- Automatic Handling
PraisonAI reconfigures stdout/stderr to UTF-8 on Windows and renders Unicode output without crashes:
bash praisonai browser doctorNo configuration needed — no
PYTHONIOENCODINGworkaround required. - Legacy Workaround (Older Releases)
Releases older than PraisonAI PR #5857 only set
PYTHONIOENCODINGfor child processes. On those versions, enable UTF-8 manually (or runpip install --upgrade praisonai):PowerShell $env:PYTHONIOENCODING='utf-8' chcp 65001 praisonai --helpCMD set PYTHONIOENCODING=utf-8 chcp 65001 praisonai --help
How It Works
| Component | Behavior | Fallback |
|---|---|---|
| Rich Console | Detects legacy code page | Uses ASCII boxes, no emoji |
| PYTHONIOENCODING | Set to utf-8 for subprocess safety | Prevents child process crashes |
_ensure_utf8_stdio() | Reconfigures current sys.stdout / sys.stderr to UTF-8 | errors="replace" writes ? for unencodable characters |
| Error Handling | Catches UnicodeEncodeError | Shows remediation hint |
Configuration Options
The automatic encoding detection requires no configuration. However, you can override behavior:
| Method | Scope | When to Use |
|---|---|---|
PYTHONIOENCODING=utf-8 | Current session | Temporary fix for full Unicode |
chcp 65001 | Current session | Enable UTF-8 code page |
| System Environment Variables | Permanent | Set PYTHONIOENCODING globally |
| Windows Terminal | Best experience | Use modern terminal instead of CMD |
Common Patterns
Problem: UnicodeEncodeError in Older Versions
Symptom:
UnicodeEncodeError: 'charmap' codec can't encode character '\u2500' in position 0Solution:
# Temporary fix
set PYTHONIOENCODING=utf-8
praisonai --help
# Or upgrade to latest version
pip install --upgrade praisonaiPattern: Permanent UTF-8 Setup
For PowerShell users:
# Add to PowerShell profile
Add-Content $PROFILE '$env:PYTHONIOENCODING="utf-8"'For CMD users:
# Set system environment variable
setx PYTHONIOENCODING utf-8Pattern: Windows Terminal Integration
Use Windows Terminal instead of legacy CMD:
// Windows Terminal settings.json
{
"profiles": {
"defaults": {
"font": {
"face": "Cascadia Code"
}
}
}
}Pattern: Training summary on cp1252
praisonai-train agents handles cp1252/ASCII automatically — the summary table swaps emoji for ASCII (PASSED / *) and falls back to plain-text rows if Rich itself can’t encode. See praisonai-train Package → Windows & non-UTF-8 Consoles for the full flow.
Best Practices
Use Windows Terminal for Best Experience
Windows Terminal provides full UTF-8 support and modern terminal features. Download from the Microsoft Store or install via winget install Microsoft.WindowsTerminal.
Set Environment Variables Permanently
Instead of setting PYTHONIOENCODING in each session, add it to your system environment variables through System Properties → Environment Variables.
Consider WSL for Unix-like Experience
Windows Subsystem for Linux (WSL) provides a full Unix terminal experience without encoding issues. Install with wsl --install.
Diagnostics: praisonai browser doctor on Windows cp1252
praisonai browser doctor runs on default PowerShell / cmd with no env-var workaround. If you still see Error: Unable to display help due to terminal encoding limitations., your release pre-dates PR #5857 — upgrade with pip install --upgrade praisonai.
Upgrade to Latest PraisonAI Version
The automatic encoding detection was added in recent versions. Ensure you’re running the latest version with pip install --upgrade praisonai.