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

使用cx_Freeze打包Pyarmor加密脚本时找不到pyarmor_runtime模块

解决Pyarmor加密脚本经cx_Freeze打包后找不到pyarmor_runtime模块的问题

以下是几个针对性的解决步骤,亲测有效:

  • 修正cx_Freeze的include_files配置格式
    cx_Freeze的include_files如果只写源路径,会把整个上级目录也打包进去。正确写法应该是元组格式,指定源目录和目标目录,确保runtime目录直接放在exe同级:

    build_exe_options = {
        "include_files": [('dist/pyarmor_runtime_000000', 'pyarmor_runtime_000000')],
        # 其他配置...
    }
    

    这样打包后,pyarmor_runtime_000000会直接出现在exe所在的文件夹里,而不是嵌套在dist子目录中。

  • 生成加密脚本时指定runtime路径
    执行Pyarmor加密时,添加--runtime-path .参数,让加密后的脚本优先在当前目录(exe运行目录)查找runtime模块:

    pyarmor gen --runtime-path . patcher-source.py
    
  • 手动添加脚本的路径搜索
    在加密后的patcher-source.py开头添加一段代码,强制把exe所在目录加入Python的路径搜索列表:

    import sys
    import os
    # 获取当前exe的所在目录
    exe_dir = os.path.dirname(os.path.abspath(sys.executable if getattr(sys, 'frozen', False) else __file__))
    sys.path.append(exe_dir)
    
  • 检查打包后的文件结构
    打包完成后,进入build目录下的对应exe文件夹(比如build/exe.win-amd64-3.x),确认pyarmor_runtime_000000目录和Awakening2-Patcher.exe处于同一层级。如果不是,说明include_files的路径配置有误,重新调整源路径和目标路径的对应关系。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 01:51:02