![](/img/trans.png)
[英]UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position XXX: char
[英]closurebuilder.py error on Windows: “can't decode byte 0x8f”
我試圖在Windows上運行closurebuilder.py,無論我傳遞什么文件,我都會從Python中得到相同的錯誤:
python goog \\ closure \\ bin \\ build \\ closurebuilder.py --root = goog / closure / goog / --root = closurebuilder-example / --namespace =“ myproject.start”
goog\closure\bin\build\closurebuilder.py: Scanning paths...
Traceback (most recent call last):
File "goog\closure\bin\build\closurebuilder.py", line 262, in <module>
main()
File "goog\closure\bin\build\closurebuilder.py", line 200, in main
sources.add(_PathSource(js_path))
File "goog\closure\bin\build\closurebuilder.py", line 175, in __init__
super(_PathSource, self).__init__(source.GetFileContents(path))
File "C:\Users\Chris\Code\Plain\goog\closure\bin\build\source.py", line 119, in GetFileContents
return fileobj.read()
File "C:\System\Python\33\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 6857: character maps to <undefined>
無論我嘗試構建簡單的腳本,空白文件還是更復雜的文件,都會發生此錯誤,抱怨字節0x8f出現UnicodeDecodeError。 我正在使用Visual Studio 2012創建這些文件,並且嘗試使用默認編碼(Windows Code Page 1252)和UTF-8進行保存。
為了使事情簡單,我嘗試在以下位置構建基本示例: https : //developers.google.com/closure/library/docs/closurebuilder
如果頁面更改,這是我使用的HTML和腳本:
HTML:
<!doctype html>
<html>
<head>
<script src="../closure-library/closure/goog/base.js"></script>
<script src="start.js"></script>
</head>
<body>
<script>
myproject.start();
</script>
</body>
</html>
JS:
goog.provide('myproject.start');
goog.require('goog.dom');
myproject.start = function() {
var newDiv = goog.dom.createDom('h1', {'style': 'background-color:#EEE'},
'Hello world!');
goog.dom.appendChild(document.body, newDiv);
};
// Ensures the symbol will be visible after compiler renaming.
goog.exportSymbol('myproject.start', myproject.start);
是什么原因造成的?
該文檔似乎沒有提到需要哪個版本的Python。 Python 3.x使用系統的默認編碼自動將文本文件解碼為Unicode,這可能會導致您在Python 3.3上看到錯誤。
試試Python 2.7。
正如@ janne-karila所建議的那樣,降級到Python 2.7對我來說是解決方案的一部分。但是,進行了更改之后,我開始出現以下錯誤:
WindowsError: [Error 2] The system cannot find the file specified
解決方案是將java.exe添加到PATH。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.