python 打包成exe执行文件
1. 在命令行用pip安装 pyinstaller包
pip install pyinstaller2.下载安装pyinstaler运行时所需要的windows扩展pywin32
mhammond/pywin32下载地址:https://github.com/mhammond/pywin32/releases
选择最新版的下载,注意要选择对应的python版本(version)和python位数(bittedness)
通过在命令行输入python查看python版本和位数
如下所示为python3.6的32位,需要下载[pywin32-223.win32-py3.6.exe]
Python 3.6.3 ... [MSC v.1900 32 bit (Intel)] on win32
如下所示为python3.6的64位,需要下载[pywin32-223.win-amd64-py3.6.exe]
Python 3.6.3 ... [MSC v.1900 64 bit (AMD64)] on win32
3.在命令行中直接输入下面的指令即可
pyinstaller [opts] yourprogram.py
参数含义
-F 指定打包后只生成一个exe格式的文件(建议写上这个参数)
-D –onedir 创建一个目录,包含exe文件,但会依赖很多文件(默认选项)
-c –console, –nowindowed 使用控制台,无界面(默认)
-w –windowed, –noconsole 使用窗口,无控制台
-p 添加搜索路径,让其找到对应的库。
-i 改变生成程序的icon图标(比如给女朋友写的程序,换个好看的图标,默认的很丑)例子:
print('hello world')
name = input("Tell me your name,and I will repeat it back to you:")
print('thank\'s ' + name)
input("will exit:")保存为first.py
执行:
pyinstaller.exe -F .\first.py版权属于:Joyber
本文链接:https://blog.qqvbc.com/default/321.html
转载时须注明出处及本声明