pip install 出现UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 73: ordinal not i

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/kezhen/article/details/21595747

RedHat 操作系统中使用pip install中出现UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 73: ordinal not in range(128),经查阅资料发现可能编码的问题

使用echo $LANG命令:

[root@localhost tools]# echo $LANG
en_US.UTF-8

可以看出系统默认语言为en_US.UTF-8

对于Python设定语言可以在site-packages中创建sitecustomize.py,Python会自动加载
[root@localhost site-packages]# pwd
/usr/local/lib/python2.7/site-packages

[root@localhost site-packages]# cat sitecustomize.py
import sys
sys.setdefaultencoding('utf-8')

如果涉及到中文只需将utf-8修改为gb2312 即可。


展开阅读全文

'ascii' codec can't encode characters in position 0-10: ordinal not in range

10-09

我写了下面的代码,首次运行后提示“'ascii' codec can't encode characters in position 0-10: ordinal not in range”,然后在网上搜了一下此问题,就在文件的顶部加入“reload(sys) sys.setdefaultencoding( "utf-8" )”,但是点击F5运行程序就什么也出不来了。rnrn# -*- coding: cp936 -*- rnimport arcpy, os,sysrnrn__name__='publishHelper' rn rn# 将指定目录下所有的.mxd文档发布为地图服务 rn# folder:包含mxd文档的文件夹路径 rn# serviceDir:服务目录URL,例如http://localhost/arcgis/rest/services rn# serviceFolder:服务所在文件夹,如果为空,则表示根目录 rndef PublishAll(folder,serviceDir,serviceFolder): rn print "检查文件夹路径……" rn if os.path.isdir(folder) == False: rn print "输入的文件夹路径无效!" rn return rn print "遍历文件夹……" rn files = os.listdir(folder) rn for f in files: rn if f.endswith(".mxd"): rn mxdPath = os.path.join(folder, f) rn print "publishing: " + f rn PublishMxd(mxdPath, serviceDir, serviceFolder) rn else: rn continue rn#将mxd文档发布为服务:1.将mxd转为msd;2.分析msd;3.发布msd rndef PublishMxd(mxdPath, serviceDir, serviceFolder): rn #检查mxd和msd文件是否存在 rn print "检查文件路径……" rn if os.path.exists(mxdPath) == False: rn print "指定路径的mxd文档不存在!" rn return rn rn # 打开mxd文档 rn try: rn print "正在打开mxd文档……" rn mxd = arcpy.mapping.MapDocument(mxdPath) rn except Exception, e: rn print "open mxd error: ", e rn return rn else: rn print "mxd文档打开成功……" rn rn # 获取默认的数据框 rn print "正在读取mxd文档默认数据框……" rn df = "" rn try: rn frames = arcpy.mapping.ListDataFrames(mxd, "图层") rn if len(frames) == 0: rn frames = arcpy.mapping.ListDataFrames(mxd, "Layers") rn df = frames[0] rn except Exception, e: rn print "读取mxd文档默认数据框失败:", e rn return rn rn # 构造msd文档名称 rn msdPath = mxdPath.replace(".mxd", ".msd") rn # 将mxd转为msd rn print "正在将mxd文档转换为msd文档……" rn arcpy.mapping.ConvertToMSD(mxd, msdPath, df, "NORMAL", "NORMAL") rn rn # 分析msd rn print "正在分析文档……" rn analysis = arcpy.mapping.AnalyzeForMSD(mxd) rn # 列出分析结果信息 rn for key in ('messages', 'warnings', 'errors'): rn print "----" + key.upper() + "---" rn vars = analysis[key] rn for ((message, code), layerlist) in vars.iteritems(): rn print " ", message, " (CODE %i)" % code rn print " applies to:", rn for layer in layerlist: rn print layer.name, rn print rn rn #获取服务器信息 rn serviceName = os.path.basename(msdPath).replace(".msd", "") rn serverName = serviceDir.split("/")[2] rn try: rn #发布msd rn print "正在发布服务……" rn arcpy.mapping.PublishMSDToServer (msdPath, serviceDir, serverName, serviceName, serviceFolder, ["WMS", "KML"]) rn except Exception, e: rn print "发布服务失败:", e rn else: rn print "服务发布成功!" rnrnPublishAll("E:\\englishFileTwo", "http://localhost:6080/arcgis/rest/services", "dlwy") 论坛

没有更多推荐了,返回首页