Sublime Text 提示[Decode error - output not utf-8]的解決方法

如題,在Sublime Text運行時報錯,提示“[Decode error - output not utf-8]”或“[Decode error - output not gbk]”,錯誤信息是腳本輸出的信息不是某種指定編碼。

解決問題思路:在解碼輸出文字編碼出錯時使用gbk試試,相當於utf-8和gbk兩種編碼都試試,這樣可以解決編碼錯誤的問題。

解決方法如下:

1.在Sublime Text的安裝目錄下的Pristine Packages目錄下找到Default.sublime-package,將這個複製出來,將後綴改名爲zip,如圖

2.解壓,然後將其中的exec.py文件放到sublime text的Data\Packages\User\目錄下,如圖

3.打開exec.py.找到類ExecCommand的append_data函數,在以下位置添加代碼

   def append_data(self, proc, data):
        if proc != self.proc:
            # a second call to exec has been made before the first one
            # finished, ignore it instead of intermingling the output.
            if proc:
                proc.kill()
            return
 
        #add start
        is_decode_ok = True;
        try:
            str = data.decode(self.encoding)
        except:
            is_decode_ok = False
        if is_decode_ok==False:
            try:
                str = data.decode("gbk")
            except:
                str = "[Decode error - output not " + self.encoding + " and gbk]\n"
                proc = None
 
        # Normalize newlines, Sublime Text always uses a single \n separator
        # in memory.
        str = str.replace('\r\n', '\n').replace('\r', '\n')
 
        self.output_view.run_command('append', {'characters': str, 'force': True, 'scroll_to_end': True})

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章