简体   繁体   English

我怎么能改变python控制台编码MAC OSX

[英]how can i change python console encoding MAC OSX

I tried all in this interesting thread Changing default encoding of Python? 我在这个有趣的线程中尝试了所有改变Python的默认编码? but nothing work for me. 但对我来说没什么用。 I use sublime text and when I try : 我使用sublime文本,当我尝试:

import sys
print(sys.stdout.encoding)

Output is : US-ASCII 输出为:US-ASCII

I have a python script that works perfectly under Windows (Output is : utf-8) 我有一个在Windows下完美运行的python脚本(输出为:utf-8)

But on osx 10.10.2, I always have a problem 但是在osx 10.10.2上,我总是遇到问题

Another thing that might help for answer, when I try in python shell (osX) this code : 另一件可能有助于回答的事情,当我在python shell(osX)中尝试这段代码时:

>>> leString = '/Users/djex/Desktop/dosser\ é\ espace'
>>> type(leString)
<class 'str'>

>>> stringNew = leString.encode('utf-8')
>>> type(stringNew)
<class 'bytes'>

>>> print (stringNew)
b'/Users/djex/Desktop/dosser\\ \xc3\xa9\\ espace'

>>> print (stringNew.decode('utf-8'))
/Users/djex/Desktop/dosser\ é\ espace
>>>

All is ok.but... 一切都好。但是......

when I try the same thing in sublime text (osX), it does not work 当我在sublime文本(osX)中尝试相同的事情时,它不起作用

i always have this error 我总是有这个错误

unicodeencodeerror 'ascii' codec can't encode character '\u0300' blabla

or error like 或错误

'str object has no attrbute decode'

I do not really understand where my problem comes 我真的不明白我的问题出在哪里

Ty for your help Ty为你的帮助

Found, my problem was in python.sublime-build file 发现,我的问题是在python.sublime-build文件中

this file does not have "env" line 这个文件没有“env”行

{
"cmd": ["python3", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"encoding": "utf-8",
"env": {"LANG": "fr_FR.UTF-8"}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM