打包包含多个文件夹的项目
1.pycharm进入该目录
2.pyi-makespec xxxx.py(主程序文件) 生成spec文件
3.修改spec对应的文件
4.pyinstaller xxx.spec 打包该项目
spec文件模板
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
import os
# path环境变量中含有python的列表
python_list = [i for i in os.environ['Path'].split(';') if 'python' in i]
sklearn_pathes = []
sklearn_lib = 'Lib\\site-packages\\sklearn\\.libs'
for i in python_list:
thepath = os.path.join(i, sklearn_lib)
if os.path.exists(thepath):
sklearn_pathes.append(thepath)
break
# 文件结构el\\src\\merge_ai_detect\\merge_file_config
added_files = [
('src\\merge_ai_detect\\merge_file_config\\', 'merge_file_config'), # 第一个是相对路径,文件存在的位置,第二个是打包后文件要保存的位置,merge_file_config文件与xx.exe文件在同一级
]
for pp in sklearn_pathes:
added_files.append((pp, '.'))
console = True # set true for better debug, set False for product
entries = ['src/merge_ai_detect/merge_file.py']
a = Analysis(
entries, # 主程序的启动路径
pathex=['.\\src\\merge_ai_detect\\'], # 相对目录,根目录下面的src\\merge_ai_detect\\,merge_ai_detect文件夹里面的所有py文件
binaries=[], # 要打包的二进制目录,一般以xxx.dll结尾
datas=added_files, # 要打包的文件夹
hiddenimports=['app_string_repair.main',
'pymssql','pkg_resources.py2_warn',
'jmespath',
'common.del_overdue_pic',
'sklearn.neighbors._typedefs',
'sklearn.utils._weight_vector',
'sklearn.neighbors._quad_tree',
'scipy.special.cython_special',
'sklearn.utils._cython_blas',
'sklearn.tree',
'sklearn.tree._utils'
], # 忽略的包,不会导入
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
exe = EXE(
pyz,
a.scripts,
[],
exclude_binaries=True,
name='autoGit', # 程序名
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)
coll = COLLECT(
exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='autoGit', # 程序名
)
参考链接:
https://blog.csdn.net/weixin_39531229/article/details/110537890
https://blog.csdn.net/Rebacca122222/article/details/124440089