1

I have recently started using emacs under Windows as my python IDE. I had some struggle getting python convinced that it was allowed to output UTF-8 to my terminal emulator (mintty does support unicode, after all) – setting PYTHONIOENCODING=UTF-8 did the trick – but my inferior python buffer still tries to force the “charmap” encoding onto python, even though emacs can deal with unicode.

>>> Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "p:/My Documents/test.py", line 33, in <module>
  File "c:\[...]\Anaconda3\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u03b5' in position 0: character maps to <undefined>

How do I tell emacs to tell python to just get on with it and use UTF-8?

1 Answer 1

3

The solution is to just set the same environment variable to the same value as in your question. How that is done I was reminded of by an answer to a previous, similar question – which I asked myself, but had forgotten about: It's as simple as adding

(setenv "PYTHONIOENCODING" "UTF-8")

to your emacs startup file.

1
  • You can also set PYTHONIOENCODING to UTF-8 in the Windows Environment Variables, and restart Emacs.
    – kotchwane
    Feb 17, 2020 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.