PyInstaller打包python

目前把python打包成exe的主流方法有: cx_Freeze PyInstaller py2exe

PyInstaller 官网 http://www.pyinstaller.org/

1.安装

C:pyinstaller-python3>setup.py install

安装前需要安装PyWin32

2.基本使用 ·生成单一exe文件:

pyinstaller.py -F ..BlogsToWordpressBlogsToWordpress.py

·添加必要的搜索路径:

1
pyinstaller.py -F -p D:tmptmp_dev_rootpythontutorial_summarymake_exeBlogsToWordpresslibs;D:tmptmp_dev_rootpythontutorial_summarymake_exeBlogsToWordpresslibscrifan;D:tmptmp_dev_rootpythontutorial_summarymake_exeBlogsToWordpresslibscrifanblogModules;D:tmptmp_dev_rootpythontutorial_summarymake_exeBlogsToWordpresslibsthirdparty;D:tmptmp_dev_rootpythontutorial_summarymake_exeBlogsToWordpresslibsthirdpartychardet; ..BlogsToWordpressBlogsToWordpress.py

·添加必要的搜索路径,且带图标:

1
pyinstaller.py -F -p D:tmptmp_dev_rootpythontutorial_summarymake_exeBlogsToWordpresslibs;D:tmptmp_dev_rootpythontutorial_summarymake_exeBlogsToWordpresslibscrifan;D:tmptmp_dev_rootpythontutorial_summarymake_exeBlogsToWordpresslibscrifanblogModules;D:tmptmp_dev_rootpythontutorial_summarymake_exeBlogsToWordpresslibsthirdparty;D:tmptmp_dev_rootpythontutorial_summarymake_exeBlogsToWordpresslibsthirdpartychardet; -i ..BlogsToWordpressBlogsToWordpress.ico ..BlogsToWordpressBlogsToWordpress.py

PS:生成的exe相对较大,加UPX壳压缩即可


参考文章: http://www.crifan.com/use_pyinstaller_to_package_python_to_single_executable_exe/