Sublime Forum

UnicodeEncodeError: 'ascii' codec can't encode characters in position

#1

I’m new to Sublime and testing it out. Unfortunately I’m facing the problem with encoding when I’m trying to run Python code with russian letters in it in Sublime. Here is a code examle:

import os, sys
print(sys.getdefaultencoding())
print('выаыва')

And this is error I’m getting:

utf-8
Traceback (most recent call last):
  File "/Users/ds/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents/test.py", line 4, in <module>
print('\u0432\u044b\u0430\u044b\u0432\u0430')
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-5: ordinal not in range(128)
[Finished in 0.1s with exit code 1]
[cmd: ['python3', '-u', '/Users/ds/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents/test.py']]
[dir: /Users/ds/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents]
[path: /usr/bin:/bin:/usr/sbin:/sbin]

This code works absolutely fine in Terminal or, for example TextMate which is my current editor.

To run this code I’m using custom built system with Python3:

{
    "cmd": ["python3", "-u", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python",
    "encoding": "utf8",
    "path": "/usr/local/bin"
}

I’m running all above on MacOS

Any idea what is wrong?

0 Likes

#2

you should probably copy the env var from the official build system

1 Like

#3

Thanks, it helped!

0 Likes