在 SublimeText 中直接运行 Python 脚本,出现以下报错提示:
Running python -u C:Documents and SettingsAdministrator桌面furl.py Traceback (most recent call last): File ".sublime_plugin.py", line 340, in run_ return self.run(**args) File ".exec.py", line 157, in run File ".exec.py", line 51, in__init__ File ".subprocess.py", line 633, in__init__ File ".subprocess.py", line 842, in _execute_child UnicodeEncodeError: ‘ascii‘ codec can‘t encode characters in position 51-52: ordinal not in range(128)
报错原因为当前 py 脚本位于包含中文字符串的路径下,解决方法为修改 exec.py 文件内容,在47行之前添加:
45 proc_env = os.environ.copy()
46 proc_env.update(env)
47for index, arg in enumerate(arg_list[:]): # added by yzh48 arg_list[index] = arg.encode(sys.getfilesystemencoding()) # added by yzh 不增加这两行,在中文字符路径下会出现编码错误。49for k, v in proc_env.iteritems():
50 proc_env[k] = os.path.expandvars(v).encode(sys.getfilesystemencoding())
exec.py位于sublime text 2的数据路径下:C:Documents and SettingsAdministratorApplication DataSublime Text 2PackagesDefault
subprocess.py位于python安装目录的lib下。
参考:http://www.sublimetext.com/forum/viewtopic.php?f=3&t=12185
原文:http://www.cnblogs.com/ifantastic/p/3247657.html
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!