0

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?

2

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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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