You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在PyInstaller的spec文件中配置contents-directory参数

PyInstaller spec文件中contents-directory参数的配置位置

要在spec文件中配置contents-directory参数以恢复旧版onedir布局,需按以下操作:

  • 生成onedir模式的spec文件(若已有可跳过):

    pyi-makespec --onedir 你的脚本文件名.py
    
  • 打开生成的spec文件,找到COLLECT代码块——这是onedir模式下负责收集打包资源的核心部分。

  • 在COLLECT的参数列表末尾添加contents_directory=".",示例如下:

    coll = COLLECT(exe,
                   a.binaries,
                   a.zipfiles,
                   a.datas,
                   strip=False,
                   upx=True,
                   upx_exclude=[],
                   name='你的脚本文件名',
                   contents_directory=".")  # 新增该参数
    

配置完成后,执行pyinstaller 你的脚本文件名.spec打包,输出的onedir目录就会采用旧版结构:所有依赖文件直接放在主输出目录中,而非默认的_internal子目录。

内容的提问来源于stack exchange,提问作者dinglei0719

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 04:54:52