-
Notifications
You must be signed in to change notification settings - Fork 0
UnicodeEncodeError on Wiindows #1
Copy link
Copy link
Open
Description
UnicodeEncodeError on Windows (works fine on Linux/WSL)
Issue
When running codesplain.py on Windows, the following error occurs:
UnicodeEncodeError: 'charmap' codec can't encode characters in position 75-77: character maps to <undefined>
This happens when writing out the structure file (or any output file with non-ASCII characters), typically under _generate_structure().
Stack Trace (Truncated)
File "codesplain.py", line 250, in _generate_structure
f.write(structure)
...
UnicodeEncodeError: 'charmap' codec can't encode characters
Environment
- OS: Windows 10/11 (PowerShell)
- Python: 3.7+ (Anaconda or system install)
- Terminal encoding: likely CP1252 (Windows default)
Workaround
Running the same command inside WSL (Ubuntu) or on Linux/macOS works fine:
wsl python3 codesplain.py /mnt/c/Users/xenomorph/emotuneSuggested Fix
Force UTF-8 encoding when writing files in the script to ensure cross-platform compatibility.
In all open(..., 'w') calls, replace with:
open(file_path, 'w', encoding='utf-8')Or explicitly set the default encoding at the top of the script (not recommended long-term):
import sys
sys.stdout.reconfigure(encoding='utf-8')Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels