Sublime Forum

ST3 python gone ascii

#1

When I attempt to run a python program in ST3 by typing ⌘-B, I am suddenly getting unicode errors, because the python installation seems to have switched to ascii.

For example, running:

import sys
print(sys.version)
print("\u2318")

I get the following output:

3.6.5 (default, Mar 29 2018, 15:38:43) 
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)]
Traceback (most recent call last):
  File "/Users/jpsteinb/Dropbox/40_chapters/shared_code/test2.py", line 4, in <module>
    print("\u2318")
UnicodeEncodeError: 'ascii' codec can't encode character '\u2318' in position 0: ordinal not in range(128)

But if I run the same program from the shell, I get…

3.6.5 (default, Mar 29 2018, 15:38:43) 
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)]
⌘

…with no error. I get similar errors as above anytime I try to print a unicode character, or read one from file.

I can’t figure out what I did—I don’t recall installing any packages, etc. I have tried quitting sublime text and even restarting the computer, to no avail.

====

EDIT: After restarting the computer a second time, the problem went away.

BUT: Five minutes later, the problem came back again. I’m getting the same error messages and did nothing in particular that I can figure out. :frowning:

0 Likes

#3

are you using the built in Python build system?

if not, maybe you need to set the PYTHONIOENCODING environment variable to utf-8 or the LANG environment variable or something

0 Likes

#4

Thank you. Indeed, relaunching sublime from the terminal with

LANG=en_US.UTF-8 sublime

solved the problem. (Note to beginners: sublime is my own alias for ST3—maybe subl on other systems, etc.)

Now it would just be nice to know what happened, lest it keep coming back…

0 Likes