Sublime Forum

Building with Python3 on OSX Strange Unicode Error

#1

Hello!

I’m trying to get running Python3 with Sublime Text 3 on OSX. Everything works fine except of an UnicodeEncodeError which I just get in Sublime but not when I manually build the file in shell.

The very simple code looks like this and can be build in shell without any errors. The file coding-python.py is encoded in latin-1 as well.

# coding=latin-1

import sys
print(sys.version)

mylist = [u'Glück', u'Spaß', u'Ähre',]
print(mylist)

In Sublime I have configured an own build systems within an project which looks like this:

{
    "build_systems":
    [
	{
		"cmd":
		[
			"/usr/local/bin/python3",
			"-u",
			"$file"
		],
		"name": "Python3",
		"encoding":"latin-1"
	  }
    ],
    "folders":
    [
	{
		"path": "."
	}
    ]
}

What I get as an output in Sublime after selecting Python3 in the Build System:

3.5.1 (default, Jan 22 2016, 08:54:32) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)]
Traceback (most recent call last):
File "/Users/a/Documents/coding-python.py", line 7, in <module>
print(mylist)
UnicodeEncodeError: 'ascii' codec can't encode character '\xfc' in position 4: ordinal not in range(128)
[Finished in 0.0s with exit code 1]
[cmd: ['/usr/local/bin/python3', '-u', '/Users/a/Documents/coding-python.py']]
[dir: /Users/a/Documents]
[path: /usr/bin:/bin:/usr/sbin:/sbin]

What I get after python3 coding-python.py

3.5.1 (default, Jan 22 2016, 08:54:32) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)]
['Glück', 'Spaß', 'Ähre']

Does somebody know whats going wrong?

0 Likes

#2

After some research I have found the error. The correct configuration has to be as follows:

{
    "build_systems":
    [
	{
		"cmd":
		[
			"/usr/local/bin/python3",
			"-u",
			"$file"
		],
		"env":
		{
			"LANG": "de_AT.UTF-8"
		},
		"name": "Python3"
	}
    ],
    "folders":
    [
	{
		"path": "."
	}
    ],
}
0 Likes