python复杂项目打包
1、安装pipinstaller
==>pip install pyinstaller
or ==> python -m pip install pyinstaller
2、新建 .spec文件
1)进入入口文件所在目录
2)pyi-makespec xx.py
3、修改文件:
1)递归遍历所有的项目py文件和常量
py_file_list = []
other_file_list = []
def getallfilesofwalk(dir):
"""使用listdir循环遍历"""
if not os.path.isdir(dir):
# print(dir)
return
dirlist = os.walk(dir)
for root, dirs, files in dirlist:
for file in files:
this_f = os.path.join(root, file)
# print(this_f)
if file.endswith(".py"):
py_file_list.append(this_f)
elif re.findall("\.xml|\.json|\.dll|\.ini|\.h", str(file)) and not re.findall("result|source|\.idea", str(file)):
fn, this_d_ = get_filename_and_dir(this_f)
# filename, this_d = get_filename_and_dir(this_d_)
# f_item = (his_d, filentame)
# if (this_d, filename) in other_file_list:
# continue
if this_d_ not in other_file_list:
other_file_list.append(this_d_)
else:
pass
2)修改 xx.spec
# -*- mode: python -*-
import sys
import os.path as osp
sys.setrecursionlimit(5000)
block_cipher = None
SETUP_DIR = 'D:\\install_test\\FASTPLOT\\'
a = Analysis(['fastplot.py',
'frozen_dir.py',
'D:\\install_test\\FASTPLOT\\lib\\app\\start.py',
'D:\\install_test\\FASTPLOT\\lib\\models\\analysis_model.py',
'D:\\install_test\\FASTPLOT\\lib\\models\\datafile_model.py',
'D:\\install_test\\FASTPLOT\\lib\\models\\data_model.py',
'D:\\install_test\\FASTPLOT\\lib\\models\\figure_model.py',
'D:\\install_test\\FASTPLOT\\lib\\models\\time_model.py',
'D:\\install_test\\FASTPLOT\\lib\\models\\mathematics_model.py',
'D:\\install_test\\FASTPLOT\\lib\\views\\constant.py',
'D:\\install_test\\FASTPLOT\\lib\\views\\custom_dialog.py',
'D:\\install_test\\FASTPLOT\\lib\\views\\data_dict_window.py',
'D:\\install_test\\FASTPLOT\\lib\\views\\data_process_window.py',
'D:\\install_test\\FASTPLOT\\lib\\views\\data_sift_window.py',
'D:\\install_test\\FASTPLOT\\lib\\views\\mathematics_window.py',
'D:\\install_test\\FASTPLOT\\lib\\views\\para_temp_window.py',
'D:\\install_test\\FASTPLOT\\lib\\views\\mainwindow.py',
'D:\\install_test\\FASTPLOT\\lib\\views\\paralist_window.py',
'D:\\install_test\\FASTPLOT\\lib\\views\\plot_window.py'],
pathex=['D:\\install_test\\FASTPLOT'],
binaries=[],
datas=[(SETUP_DIR+'lib\\icon','lib\\icon'),(SETUP_DIR+'data','data')],
hiddenimports=['pandas','pandas._libs','pandas._libs.tslibs.np_datetime','pandas._libs.tslibs.timedeltas',
'pandas._libs.tslibs.nattype', 'pandas._libs.skiplist','scipy._lib','scipy._lib.messagestream'],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='fastplot',
debug=False,
strip=False,
upx=True,
console=True)
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='fastplot')
4、打包:pyinstaller xxx.spec
5、按需添加未正常添加的包和常量,如配置表等。
参考:https://www.cnblogs.com/shiyongge/p/10582552.html

浙公网安备 33010602011771号