1.安装所需依赖
pip install pyinstaller
pip install pypiwin32
2.使用以下命令生成spec文件
# test.py 为你的脚本
pyinstaller -F test.py
3.修改spec文件
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
# audio-only_client.py 为你的脚本
a = Analysis(['audio-only_client.py'],
pathex=[],
binaries=[],
datas=[('libopus-0.dll','.')],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='w',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None )
4.使用命令生成exe可执行文件
# w.spec 为上一步生成的spec文件, dir后的为 upx 解压路径
pyinstaller -F w.spec --upx-dir C:\setup\Python\upx394w
?
?到此为止 ,你已经成功将脚本转换为可执行文件了
|