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

PyInstaller编译代码时触发KeyError: 'CALL_FUNCTION'错误求助

PyInstaller编译报错KeyError: 'CALL_FUNCTION'的解决方法

问题描述

使用PyInstaller编译Python代码时触发KeyError: 'CALL_FUNCTION'错误,已安装wheel模块及所有必要依赖,代码本身无问题,但编译其他程序时也出现相同错误,未找到相关解决方案。

错误回溯(中文翻译版)

回溯(最近的调用最后):
  文件 "<frozen runpy>", line 198, in _run_module_as_main
  文件 "<frozen runpy>", line 88, in _run_code
  文件 "C:\Users\user\AppData\Local\Programs\Python\Python311\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
  文件 "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller\__main__.py", line 107, in run
    parser = generate_parser()
             ^^^^^^^^^^^^^^^^^
  文件 "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller\__main__.py", line 78, in generate_parser
    import PyInstaller.building.build_main
  文件 "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller\building\build_main.py", line 35, in <module>
    from PyInstaller.depend import bindepend
  文件 "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller\depend\bindepend.py", line 26, in <module>
    from PyInstaller.depend import dylib, utils
  文件 "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller\depend\utils.py", line 33, in <module>
    from PyInstaller.depend import bytecode
  文件 "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller\depend\bytecode.py", line 95, in <module>
    _call_function_bytecode = bytecode_regex(rb"""
                              ^^^^^^^^^^^^^^^^^^^^
  文件 "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller\depend\bytecode.py", line 60, in bytecode_regex
    pattern = re.sub(
              ^^^^^^^
  文件 "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\re\__init__.py", line 185, in sub
    return _compile(pattern, flags).sub(repl, string, count)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  文件 "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller\depend\bytecode.py", line 62, in <lambda>
    lambda m: _instruction_to_regex(m[1].decode()),
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  文件 "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller\depend\bytecode.py", line 40, in _instruction_to_regex
    return re.escape(bytes([dis.opmap[x]]))
                            ~~~~~~~~~^^^
KeyError: 'CALL_FUNCTION'

解决方法

这个错误的核心原因是Python 3.11移除了CALL_FUNCTION字节码指令,而旧版本的PyInstaller仍在尝试引用这个已废弃的指令。解决步骤如下:

  • 升级PyInstaller到支持Python 3.11的稳定版本:
    pip install --upgrade pyinstaller
    
  • 如果升级稳定版后问题仍存在,尝试安装PyInstaller的开发版(修复了更多Python 3.11兼容问题):
    pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
    
  • 检查Python环境,确保使用的pip与当前Python版本对应(避免多版本Python导致依赖安装错位),可以用python -m pip install --upgrade pyinstaller替代直接调用pip。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.19 18:50:32