一、安装pyinstaller
在Pycharm客户端上,File-Settings-Project:Python-Project Interpreter添加PyInstaller源。如图:
二、安装压缩软件upx
下载地址:https://github.com/upx/upx/releases/tag/v3.93
解压到要转换到的py文件目录下
三、创建.py文件
from PyInstaller.main import run
if name == ‘main’:
opts = [r’E:\workspace\Python\Learns\MyFrame.py’,
‘-F’,’-w’,r’–distpath=E:\workspace\Python\Learns’,
r’–workpath=E:\workspace\Python\Learns’,
r’–specpath=E:\workspace\Python\Learns’,
r’–icon=E:\workspace\Python\Learns\exe.ico’,
r’–upx-dir’,‘upx393w’]
run(opts)
1
2
3
4
5
6
7
8
9
四丶pots参数
-F 制作独立的可执行程序
-D 制作出的档案存放在同一个文件夹下(默认值)
-K 包含TCL/TK(对于使用了TK的,最好加上这个选项,否则在未安装TK的电脑上无法运行)
-w 制作窗口程序
-c 制作命令行程序(默认)
-X 制作使用UPX压缩过的可执行程序(推荐使用这个选项,需要下载UPX包,解压后upx.exe放在Python(非PyInstaller)安装目录下,下载upx308w.zip)