sublime text2 UnicodeDecodeError: 'ascii' codec can't decode byte 0xc0 in...错误解决

来源:互联网 发布:程序员改bug 动图 编辑:程序博客网 时间:2024/05/18 03:20

文章参考:http://eric.themoritzfamily.com/python-encodings-and-unicode.html

http://desert3.iteye.com/blog/757508

https://github.com/misfo/Shell-Turtlestein/issues/6

http://www.sublimetext.com/forum/viewtopic.php?f=3&t=2610

https://github.com/uipoet/sublime-jshint/issues/24

http://www.sublimetext.com/forum/viewtopic.php?f=3&t=2441&start=0&hilit=getfilesystemencoding(*)

完整的错误是:

Traceback (most recent call last):
  File ".\sublime_plugin.py", line 325, in run_
  File ".\exec.py", line 145, in run
  File ".\exec.py", line 42, in __init__
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc0 in position 9: ordinal not in range(128)


这些文章很多是有重复内容的,我主要看的是后面标*的那一篇;

这个问题的起因是配置文件目录下Packages\Default目录下的exec.py在编辑环境变量,但是环境变量中的字符集确少了ascii字符集

我的解决方案(参靠上面第6篇):

找到配置文件目录位置(可以参考我的另一篇博文修改sublime Text 的默认配置文件位置

其中的Packages\Default\exec.py,打开编辑

找到第41-42行:

for k, v in proc_env.iteritems():

 proc_env[k] = os.path.expandvars(v).encode(sys.getfilesystemencoding())

两种修改方案:

1、果断删掉!(你没看错,就是这样)

2、对它进行异常处理,避免它出错时停止程序运行就像这样:

     for k, v in proc_env.iteritems():
            try:
                proc_env[k] = os.path.expandvars(v).encode(sys.getfilesystemencoding())
            except UnicodeDecodeError:
                print "Encoding error..."
                print "VARIABLE: ", k, " : ", v

然后你在尝试对pyhon或是其他程序的编译,就会发现切正常了!

原创粉丝点击