快速打包python
因为经常写一些python的小脚本,然后在windows上运行,但是每次都python main.py,未免有些麻烦,所以写了一个小脚本,可以打包python成单个exe文件。
import os
import shutil
import glob
path = input("输入您的目标程序路径:")
str = "pyinstaller --onefile "+path
os.system(str)
print("输出成功!")
shutil.rmtree("build")
print("清除成功!")
spec_files = glob.glob('*.spec')
for file in spec_files:
file_path = os.path.abspath(file) # 获取文件的绝对路径
try:
os.remove(file_path) # 删除文件
print(f'成功删除文件: {file_path}')
except OSError as e:
print(f'删除文件时出错: {file_path} - {e.strerror}')
其他的设置可以根据需要自行调整,这里只需要拖动你的python文件地址,就能直接打包~,然后会将打包产生的过程文件给删除,最终的输出位于dist文件夹内。
只需要此工具的可以前往此处下载:打包exe下载