pyinstaller打包多文件夹程序

打包包含多个文件夹的项目
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

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值