最近改公司的一个项目,用到了第三方库xlrd,安装之后在Sublime中运行一直出错:
Traceback (most recent call last):
File "/Users/FlyElephant/Desktop/FlyElephant.py", line 3, in <module>
import xlrd
ImportError: No module named xlrd
Sublime Text2中默认查找python的路径变量是PATH变量,所有有些设置$path的答案是走不通的,需要Preference/Browse Packages/Python的Python.sublime-build文件在其中加上:
"env":
{
"PYTHONPATH":"/usr/local/lib/python:/usr/local/lib/python2.7/site-packages"
}
2.读取Excel会输出可能会遇到字符串编码问题
UnicodeEncodeError: 'ascii' codec can't encode characters in position 4-7: ordinal not in range(128)
解决方式如下:
import sys
reload(sys)
sys.setdefaultencoding( "utf-8" )