[via] Changing default encoding of Python? - StackOverflow
I ran into an issue using llm today where I was unable to save a response to a file using a pipe
llm llm logs -n 1 | Out-File response.txt
This would give me the error "UnicodeEncodeError: 'charmap' codec can't encode character '\u2192' in position 2831: character maps to <undefined>"
If you set the "PYTHONIOENCODING" environment variable to "utf8", it will fix the issue. This is because Python's default encoding is ASCII. Since the last response I got back from the model contained a non-ASCII character, this error was thrown.
So now, in my PowerShell profile, I've added a line to set the default to utf8, which fixes the issue.
$env:PYTHONIOENCODING = 'utf8'