无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

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

分享到微博請遵守國家法律
涟源市| 化隆| 永定县| 西宁市| 华亭县| 隆尧县| 陵川县| 康乐县| 翁源县| 七台河市| 秦安县| 新田县| 榆树市| 子洲县| 平顺县| 永州市| 宣化县| 宁远县| 新龙县| 咸丰县| 桃园县| 广丰县| 富宁县| 连平县| 镇宁| 普陀区| 巴南区| 郧西县| 台南县| 清丰县| 景洪市| 新兴县| 墨脱县| 新宁县| 浮梁县| 红安县| 南江县| 北安市| 慈溪市| 滨海县| 溧阳市|