PyInstaller,可将py脚本转换为exe

整理自:http://blog.csdn.net/hmy1106/article/details/45151409 

本文PyInstaller的版本是2.0,支持Python2.7。下面讨论怎样安装、使用PyInstaller。PyInstaller本身并不属于Python包。在安装 pyinstaller 之前假设你已经安装了python ,注意把python 环境变量配置好, 即 进入cmd后 输入 python 会进入 python  shell.

 

PyInstaller下载地址:https://pypi.python.org/pypi/PyInstaller, (3.1版本,解压就可以了)。

 

进入cmd , 

d:pyinstaller>python pyinstaller.py  

Usage: python pyinstaller.py [opts] <scriptname> [ <scriptname> ...] | <specfile>   
pyinstaller.py: error: Requires at least one scriptname file or exactly one .spec-file

……

 

以上信息表示可以开展工作了,以下是测试一个demo.py 文件的打包,文件放在当前目录的pyinstaller文件夹里面 .

d:pyinstaller>python pyinstaller.py --console --onefile  demo.py  

 

上面的命令成功运行后,demo.py 会生成一个demo文件夹。在这个文件夹下面会有一个名为dist的文件夹,此文件夹下面有转换好的demo.exe。

 

点击 demo.exe,首先会出来一个 控制台的黑窗口,如下图:

 

上面编译出来的exe能够正常运行了,但带一个黑色的console,以下重新编译,加入--windowed --icon,取消--console    

D:PyInstaller>python pyinstaller.py  -w  --onefile --icon="my.ico" demo.py  

icon是你喜欢的图标文件,py为你要打包的程序。最后生成一个demo.exe可执行文件,点击demo.exe直接显示所绘图形。

 

原文地址:https://www.cnblogs.com/ant-wjf/p/5782001.html