网站图片引导页怎么做,西安网站制作资源,烟台商城网站建设,天蝎网站建设公司说明#xff1a; 自动获取当前根目录下所有py文件生成spec文件#xff0c;直接运行pyinstaller进行打包即可。直接打包成单执行文件。 直接上代码 
import ospathex  []def recursion(path, main):if path[:1] ! /:path  /listpath  os.listdir(path)for item in listpath:if…说明 自动获取当前根目录下所有py文件生成spec文件直接运行pyinstaller进行打包即可。直接打包成单执行文件。 直接上代码 
import ospathex  []def recursion(path, main):if path[:1] ! /:path  /listpath  os.listdir(path)for item in listpath:if os.path.isdir(path  item):recursion(path  item, main)# print(文件夹,path item)elif os.path.isfile(path  item):# if .py in item and .pyc not in item and __init__ not in item and .pyz not in item and main not in item:if .py in item and all(i not in item for i in [.pyc, __init__, .pyz,.pyd, main]):# print(文件,path item)pathex.append(path  item)else:print(未知文件, path  item)def getTxt():return # -*- mode: python ; coding: utf-8 -*-
block_cipher  Nonea  Analysis([${thisMain}.py],pathex${thisPath},binaries[],datas[],hiddenimports${thisPy},             runtime_hooks[],excludes[],win_no_prefer_redirectsFalse,win_private_assembliesFalse,cipherblock_cipher,noarchiveFalse)
pyz  PYZ(a.pure, a.zipped_data,cipherblock_cipher)
exe  EXE(pyz,a.scripts,a.binaries,a.zipfiles,a.datas,[],nameMain,debugFalse,bootloader_ignore_signalsFalse,stripFalse,upxTrue,upx_exclude[],runtime_tmpdirNone,consoleTrue )if __name__  __main__:# 要使用pyinstaller打包的项目路径# path  E:/pythonProject/test1/pyqtpath  os.path.dirname(__file__)# 打包项目的入口文件名main  mainrecursion(path, main)hiddenimports  []for i in pathex:if i ! path:# print(i[:i.rindex(/)])hiddenimports.append(i.replace(i[:i.rindex(/)], ).replace(i[i.index(.):], ).replace(/, ))pathexs  []pathex.append(path)for i in pathex:if i ! path:pathexs.append(i.replace(os.path.abspath(os.path.join(os.getcwd(), ../)), ).replace(/, \\))continuepathexs.append(i.replace(/, \\))outTxt  getTxt().replace(${thisPy},f{hiddenimports}).replace(${thisPath},f{pathexs}).replace(${thisMain},main)with open(f{path}/{main}.spec,w,encodingutf-8)as f:f.write(outTxt)f.close()exit(0) 
打包后的spec文件怎么使用 直接在terminal窗口执行 pyinstaller 文件名.spec 然后回车即可