5

While trying to run a python script in an Inferior Python buffer for Python 3.3.5 in my Emacs 24.3.1 GTK+ window, I get a

>>> Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.3/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1332:
 ordinal not in range(128)

This even happens when all my buffer contains is the minimum to make it a python script containing a unicode character.

#!/usr/bin/env python3
"ε"

There appears to also be some magic that replaces all non-ascii characters from the first line (?) of input with whitespace, because just

"ε"

gives me the string " ", trying to do ε=4 results in an IndentationError, and ord("ε") on the first line of a file returns 32. This may be related; however, if the non-ascii symbols appear after the first line, all these constructions result in a UnicodeDecodeError instead.

As you can see, I haven't even started outputting any unicode symbols, and the Inferior Python buffer accepts input of unicode characters. Running the same python script in a terminal (urxvt or a random tty) works without problems as well.

What do I need to change to make it work?

1
  • For the sake of completeness, could you add the content of the Python buffer that causes the trouble? The shorter the example that triggers the error, the better. Also make sure you try running with emacs -Q.
    – paprika
    Commented Nov 25, 2014 at 16:08

1 Answer 1

3

You can define the encoding in your .emacs using the following environment variables:

(setenv "LANG" "en_US.UTF-8")
(setenv "LC_ALL" "en_US.UTF-8")
(setenv "LC_CTYPE" "en_US.UTF-8")
1
  • You saved the day! Commented Apr 18, 2015 at 14:40

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.