利用PyInstaller将python程序.py转为.exe的方法详解
前言
最近经常用到一个.py程序,但是每次在不同电脑上用,希望能把Python脚本发布为脱离Python平台运行的可执行程序,比如单个exe。PyInstalle满足要求。
PyInstaller本身并不属于Python包。在安装 pyinstaller之前需把python环境配置好。
安装pyinstaller
下载pyinstaller
解压到F:\PyInstaller-2.1(自选)(可以去官网下载最新版)
安装pywin32
pywin32-217.win32-py2.7.exe:点击下载
安装pyinstaller
1、进入cmd
cd F:\PyInstaller-2.1
python pyinstaller.py --console --onefile test.py
如果提示:
Usage: python pyinstaller.py [opts] [ …] | pyinstaller.py: error: Requires at least one scriptname file or exactly one .spec-file
则说明安装完成了。
测试打包
1、文件放在当前目录的pyinstaller-2.1文件夹里面
cd F:\PyInstaller-2.1
python pyinstaller.py --console --onefile test.py
2、命令运行成功后会生成一个test文件夹。在这个文件夹下面会有一个名为dist的文件夹,此文件夹下面有转换好的test.exe
3、上面编译出来的exe能够正常运行了,但带一个黑色的console,以下重新编译,加入?Cwindowed ?Cicon,取消?Cconsole
python pyinstaller.py -w --onefile --icon="my.ico" test.py
其中my.ico是你要给他加的自定义图标文件。
总结
上一篇:win7下 python3.6 安装opencv 和 opencv-contrib-python解决 cv2.xfeatures2d.SIFT_create() 的问题
栏 目:Python代码
下一篇:PyQt5的安装配置过程,将ui文件转为py文件后显示窗口的实例
本文标题:利用PyInstaller将python程序.py转为.exe的方法详解
本文地址:http://www.codeinn.net/misctech/63809.html






