最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊

基于pyinstaller的自動(dòng)打包單文件程序(os,shutil庫練習(xí))(1)

2023-06-13 16:56 作者:茶座今天喝什么  | 我要投稿

20230613?

【使用說明】

將該程序放置在需要打包的py文件運(yùn)行

【功能】

1.?自動(dòng)查詢當(dāng)前路徑下的python文件

2.?輸入python文件名自動(dòng)打包

【注意】

1. 非虛擬環(huán)境,打包后文件大小比較大

2.?需要據(jù)情況修改cmd_install中的命令

【代碼】

import os

import shutil


class SingleFilePackage:

? ? def __init__(self):

? ? ? ? current_path = self.get_current_path()

? ? ? ? current_pyfile = self.get_current_pyfile(current_path)

? ? ? ? print(f'當(dāng)前路徑:{current_path}')

? ? ? ? print(f'當(dāng)前pyfile:{current_pyfile}')


? ? ? ? packfile = input('打包文件:')

? ? ? ? self.cmd_intaller(current_path, packfile)

? ? ? ? self.move_exe(current_path)

? ? ? ? self.remove_dirs(current_path, packfile)

? ?

? ? @staticmethod

? ? def get_current_path():

? ? ? ? return os.getcwd()

? ?

? ? def get_current_pyfile(self, path):

? ? ? ? files = os.listdir(path)

? ? ? ? pyfiles = []

? ? ? ? for file in files:

? ? ? ? ? ? if file[-3:] == '.py' and file != os.path.basename(__file__):

? ? ? ? ? ? ? ? pyfiles.append(file)

? ? ? ? return pyfiles

? ?

? ? def cmd_intaller(self, path, packfile):

? ? ? ? full_path = os.path.join(path, packfile)

? ? ? ? command = f'python D:\python\Scripts\pyinstaller.exe -F {full_path}'

? ? ? ? try:

? ? ? ? ? ? os.system(command)

? ? ? ? except:

? ? ? ? ? ? print('打包失敗')

? ? ? ? else:

? ? ? ? ? ? print('打包成功')

? ?

? ? def move_exe(self, move_path):

? ? ? ? move_file = os.listdir(os.path.join(move_path, 'dist'))[0]

? ? ? ? move_file = os.path.join(move_path, 'dist', move_file)

? ? ? ? try:

? ? ? ? ? ? shutil.move(move_file, move_path)

? ? ? ? except:

? ? ? ? ? ? print('移動(dòng)可執(zhí)行文件成功')


? ? def remove_dirs(self, path, file):

? ? ? ? try:

? ? ? ? ? ? dist = os.path.join(path, 'dist')

? ? ? ? ? ? build = os.path.join(path, 'build')

? ? ? ? ? ? filename = os.path.splitext(file)[0]

? ? ? ? ? ? spec_file = os.path.join(path ,f'{filename}.spec')

? ? ? ? except:

? ? ? ? ? ? pass

? ? ? ? else:

? ? ? ? ? ? shutil.rmtree(dist)

? ? ? ? ? ? shutil.rmtree(build)

? ? ? ? ? ? os.remove(spec_file)


if __name__ == '__main__':

? ? run = SingleFilePackage()



基于pyinstaller的自動(dòng)打包單文件程序(os,shutil庫練習(xí))(1)的評論 (共 條)

分享到微博請遵守國家法律
历史| 东源县| 东安县| 柘城县| 天水市| 开原市| 卓尼县| 九寨沟县| 营山县| 射洪县| 太湖县| 松江区| 大宁县| 新泰市| 双桥区| 巴塘县| 龙南县| 贵溪市| 霍林郭勒市| 蛟河市| 邵阳县| 武川县| 奉贤区| 巴中市| 阳曲县| 静乐县| 天门市| 麦盖提县| 安福县| 曲松县| 涿鹿县| 淅川县| 南雄市| 白银市| 枣阳市| 聂荣县| 厦门市| 广安市| 弥渡县| 舒城县| 淮阳县|