Python打包为exe使用py2exe时中文乱码问题

解决步骤

1.打开Python安装目录下的 Python27\Lib\site-packages文件夹,例如:C:\Python27\Lib\site-packagessize
新建文本文档重命名为:sitecustomize.py 用记事本编辑文档,内容为:

[python]  view plain  copy
  1. #!/usr/bin/env python  
  2. # coding=utf-8  
  3.   
  4. import sys  
  5. sys.setdefaultencoding(''utf-8'')  

2.将需要打包的源文件内的中文输出全部改写为以下的格式:

[python]  view plain  copy
  1. print unicode('成功:','utf-8')  
  2. print unicode(strName,'utf-8')  
  3. #strName 是字符串  

3.按照常规步骤打包为exe即可

猜你喜欢

转载自blog.csdn.net/smile_raccoon/article/details/52020706