使用PyInstaller 将python程序 .py转为 .exe

本文来自 Alliot's blog
最近常常用到一个.py程序,可是每次在不一样电脑上用,但愿能把Python脚本发布为脱离Python平台运行的可执行程序,好比单个exe。PyInstalle知足要求。
PyInstaller自己并不属于Python包。在安装 pyinstaller以前需把python环境配置好。html

安装pyinstaller

下载pyinstaller

解压到F:PyInstaller-2.1(自选)(能够去官网下载最新版)python

安装pywin32

pywin32-217.win32-py2.7.exe:点击下载post

安装pyinstaller

  一、进入cmd测试

cd F:\PyInstaller-2.1
python pyinstaller.py --console --onefile  test.py

若是提示:ui

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

则说明安装完成了。code

测试打包

  一、文件放在当前目录的pyinstaller-2.1文件夹里面htm

cd F:\PyInstaller-2.1
python pyinstaller.py --console --onefile  test.py

  二、命令运行成功后会生成一个test文件夹。在这个文件夹下面会有一个名为dist的文件夹,此文件夹下面有转换好的test.exe
  三、上面编译出来的exe可以正常运行了,但带一个黑色的console,如下从新编译,加入--windowed --icon,取消--consoleblog

python pyinstaller.py  -w  --onefile --icon="my.ico" test.py

其中my.ico是你要给他加的自定义图标文件。ip

相关文章
相关标签/搜索