-->

Unicode Encode Error in Sublime Text 3 console

2019-04-02 05:35发布

问题:

I’m always getting a

'UnicodeEncodeError: 'ascii' codec can't encode character '\xf6' in position 0: ordinal not in range(128)'

in the sublime text 3 console when trying to print a non-ascii character. I'm using Anaconda Python Builder to build the system. Building the system with the built-in “python” runs perfectly (i.e. prints out non-ascii characters fine) and also running the script from the terminal works fine (i'm running the script on Mac OS Sierra).

I assume the problem must have something to do with the Anaconda Python Builder and I thought adding the default encoding to the Anaconda.sublime-settings might help, but it doesn’t :-( Here is my anaconda user settings file:

{ "python_interpreter": "/usr/local/bin/python3.6", "anaconda_linting": false, "pep8": false, "default_encoding": "UTF-8" }

I would very much appreciate if you could help me along in this matter as I’m searching for a solution for two days now without success :-(

Thank you! Chris

回答1:

Alright, I found a way to do it:

  • Install this plugin: https://packagecontrol.io/packages/Environment%20Settings

  • Change the user settings for that EnvironmentSettings plugin to look like this:

    { "env": { "Darwin": { "LC_ALL": "en_US.UTF-8" } } }