Chr*_*ini 1 python windows utf-8 google-closure-compiler
我试图在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>
Run Code Online (Sandbox Code Playgroud)
无论我是在尝试构建一个简单的脚本,一个空白文件,还是一些更复杂的东西,都会出现这个错误,抱怨带有字节0x8f的UnicodeDecodeError.我正在使用Visual Studio 2012来创建这些文件,并且我尝试使用其默认编码(Windows代码页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>
Run Code Online (Sandbox Code Playgroud)
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);
Run Code Online (Sandbox Code Playgroud)
可能是什么导致了这个?
文档似乎没有提到需要哪个版本的Python.Python 3.x使用系统的默认编码将文本文件自动解码为Unicode,这可能导致您在Python 3.3上看到的错误.
试试Python 2.7.