ny3259 发表于 2015-12-3 11:25:37

Python 程序打包发布(PyInstaller-2.1)

  我这里UI开发是用的PySide开发的。
  程序写完需要发布。开始想用py2exe简单的程序还可以,程序一旦很多包的时候就各种错误。
  最后选择了PyInstaller。
  
  这里PyInstaller要依赖:Download Python Win32 Extensions
  官网地址:http://starship.python.net/~skippy/win32/Downloads.html
  我这里用的Python 2.7: http://liquidtelecom.dl.sourceforge.net/project/pywin32/pywin32/Build%20219/pywin32-219.win32-py2.7.exe
  
  UPX 解压后放到pyinstaller安装目录下,发布exe文件时,压缩文件用的。
  下载地址: http://upx.sourceforge.net/#downloadupx
  
  PyInstaller下载地址:https://pypi.python.org/packages/source/P/PyInstaller/PyInstaller-2.1.tar.gz#md5=248531f6fc94b0ffb02473321496d6d0
  用pip命令安装: pip install pyinstaller       也可以执行setup.py install命令安装。
  出现了:ascii code can't decode bute 0xb0的报错
  解决方法:打开C:\Python27\Lib下的 mimetypes.py 文件,找到大概256行(你可以用Notepad++的搜索功能)的‘default_encoding = sys.getdefaultencoding()’。
  在这行前面添加三行: 



if sys.getdefaultencoding() != 'gbk':
reload(sys)
sys.setdefaultencoding('gbk')
default_encoding = sys.getdefaultencoding()
  保存退出,重新执行:pip install pyinstaller
  Done!!!
  
  现在的新版本,不需要生成spec文件了。直接一个命令搞定。
  python pyinstaller.py -F -w test.py
  这里-w是不生成console窗口,仅显示UI。
  最后生成的exe文件在:D:\Python27\Lib\site-packages\PyInstaller-2.1\PyInstaller\dist\xxxx.exe 这个路径控制台会打印的。
  
页: [1]
查看完整版本: Python 程序打包发布(PyInstaller-2.1)