適合單py文件的pyinstaller一鍵自動懶人打包
【說明】:自動搜尋同路徑下的py文件,調(diào)用終端使用pyinstaller進行打包,將打包后的可執(zhí)行文件從dist文件夾移動到當(dāng)前目錄,并移除dist、build文件夾和spec文件
【使用注意】:1.?需要pyinstaller;2.?當(dāng)前目錄只有一個py文件
【使用方法】:放在需要打包的py文件相同目錄下運行
代碼:
import os
import shutil
def upgrade():
? ? pyfilename = [f for f in os.listdir()
? ? ? ? ? ? ? if '.py' in f and f != os.path.basename(__file__)][0]
? ? filename = pyfilename[:-3]
? ? # terminal
????# 視情況修改
? ? c = f'python D:/python/Scripts/pyinstaller.exe -F {pyfilename}'
? ? os.system(c)
? ? if os.path.exists(f'{filename}.exe'):
? ? ? ? os.remove(f'{filename}.exe')
? ? move_file_path = f'dist/{filename}.exe'
? ? move_path = os.getcwd()
? ? shutil.move(move_file_path, move_path)
? ? shutil.rmtree('dist')
? ? shutil.rmtree('build')
? ? os.remove(f'{filename}.spec')
upgrade()
標(biāo)簽:pythonpyinstaller