五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(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)的評論 (共 條)

分享到微博請遵守國家法律
长阳| 万州区| 临泽县| 河东区| 云南省| 黄骅市| 阳城县| 高雄市| 镇安县| 修文县| 林州市| 嘉义县| 岳阳县| 秦安县| 友谊县| 英德市| 辉县市| 黎川县| 武夷山市| 永年县| 宁强县| 花莲县| 泾源县| 石门县| 威远县| 涿鹿县| 麻江县| 专栏| 西青区| 民县| 绵竹市| 油尖旺区| 临颍县| 太谷县| 长治县| 中山市| 门头沟区| 徐水县| 乐至县| 班玛县| 浦东新区|