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'.
graph LR
subgraph "Windows Terminal Encoding"
Request[📋 User Request] --> Process[⚙️ Windows Terminal Encoding]
Process --> Result[✅ Result]
end
classDef input fill:#6366F1,stroke:#7C90A0,color:#fff
classDef process fill:#189AB4,stroke:#7C90A0,color:#fff
classDef output fill:#10B981,stroke:#7C90A0,color:#fff
class Request input
class Process process
class Result outputfrom 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.
graph LR
subgraph "Windows Terminal Encoding"
In[📝 Unicode Output] --> Detect[🔍 Detect Code Page]
Detect --> Safe[⚙️ ASCII-safe Render]
Safe --> Agent[🤖 Agent]
Agent --> Out[✅ No Crash]
end
classDef input fill:#6366F1,stroke:#7C90A0,color:#fff
classDef process fill:#F59E0B,stroke:#7C90A0,color:#fff
classDef agent fill:#8B0000,stroke:#7C90A0,color:#fff
classDef output fill:#10B981,stroke:#7C90A0,color:#fff
class In input
class Detect,Safe process
class Agent agent
class Out outputDetection Flow
graph TB
Start[praisonai --help] --> Detect{Windows +<br/>legacy code page?}
Detect -->|No| Rich[Full Rich output<br/>emoji + box drawing]
Detect -->|Yes| Safe[Safe Console<br/>ASCII box, no emoji]
Safe --> Fallback{Still<br/>UnicodeEncodeError?}
Fallback -->|No| Safe
Fallback -->|Yes| Hint[Print remediation:<br/>set PYTHONIOENCODING=utf-8]
classDef input fill:#6366F1,stroke:#7C90A0,color:#fff
classDef decision fill:#F59E0B,stroke:#7C90A0,color:#fff
classDef success fill:#10B981,stroke:#7C90A0,color:#fff
classDef warning fill:#8B0000,stroke:#7C90A0,color:#fff
class Start input
class Detect,Fallback decision
class Rich,Safe success
class Hint warningTwo-Layer Mitigation
Every Typer command passes through two layers on Windows, so Unicode output never crashes the CLI.
graph TB
Start[Any praisonai Typer command] --> Win{Windows?}
Win -->|No| Pass[macOS / Linux unchanged]
Win -->|Yes| Env[Set PYTHONIOENCODING=utf-8<br/>for child processes]
Env --> Reconfig[_ensure_utf8_stdio reconfigures<br/>current sys.stdout / sys.stderr]
Reconfig --> Rich[Rich / Typer prints Unicode safely]
Rich --> Ascii{Still can't encode?}
Ascii -->|No| Done[Render completes]
Ascii -->|Yes| Fallback[Doctor-side ASCII fallback<br/>OK / X markers]
Fallback --> Done
classDef entry fill:#6366F1,stroke:#7C90A0,color:#fff
classDef decide fill:#F59E0B,stroke:#7C90A0,color:#fff
classDef safe fill:#189AB4,stroke:#7C90A0,color:#fff
classDef ok fill:#10B981,stroke:#7C90A0,color:#fff
class Start entry
class Win,Ascii decide
class Env,Reconfig,Fallback safe
class Pass,Rich,Done okWhat 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
sequenceDiagram
participant CLI as PraisonAI CLI
participant Console as Rich Console
participant Terminal as Windows Terminal
CLI->>Console: Initialize with legacy_windows=True
Console->>Terminal: Detect code page
Terminal-->>Console: CP1252/CP850/ASCII
Console->>Console: Enable safe_box, no emoji
Console-->>CLI: ASCII-safe rendering
CLI-->>Terminal: Success (no crash)| 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.