0

Just starting to use PowerShell on Windows 10 with the latest Anaconda3 and Python3.7 and cannot run the script due to encoding error. The script attempts to write a text file which contains some German characters and throws:

UnicodeEncodeError: 'charmap' codec can't encode character '\u0144' in position 10: character maps to <undefined>

I have tried chcp 65001 and setting set PYTHONIOENCODING=utf-8 but this does not help. How does it work with PowerShell?

minerals
  • 5,609
  • 15
  • 58
  • 100

1 Answers1

1

That's a Python error not a Powershell error. If it was a Powershell issue, you'd get an exception that would look something like...

Attempted to divide by zero.
At line:1 char:1
+ 1/0
+ ~~~
    + CategoryInfo          : NotSpecified: (:) [], RuntimeException
    + FullyQualifiedErrorId : RuntimeException

Sabbir Ahmed gave a solution to this error (on Windows 10) in this post. You probably have a line that looks something like...

with open('filename', 'w') as f:
  ...

Change it to...

with open('filename', 'w', encoding='utf-8') as f:
  ...

A-

Adam
  • 3,397
  • 2
  • 13
  • 39