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

执行conda build时遭遇TypeError: create_function()参数错误

Conda Build 报错:TypeError: create_function() got an unexpected keyword argument 'narg'

问题背景

使用conda build构建基于PyPI下载的tar.gz包的recipe时触发该错误,已简化recipe复现问题,确认包的下载链接与sha256校验值无误,且在标准Python、Miniforge、Anaconda环境中均出现相同报错。

完整报错栈

(binda) C:\Users\jlcas\PythonProjects\binda>conda build binda 
警告:conda_build_config.yaml中未指定numpy版本。
使用默认numpy版本1.22 加载internal_defaults中的变体信息 尝试为binda完成元数据处理

# >>>>>>>>>>>>>>>>>>>>>> 错误报告 <<<<<<<<<<<<<<<<<<<

    回溯(最近的调用最后):
      文件 "C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda_index\index\convert_cache.py",
第158行,在remove_prefix函数中
        conn.create_function("migrate_basename", narg=1, func=basename, deterministic=True)
      文件 "C:\ProgramData\mambaforge-pypy3\Lib\_sqlite3.py", 第324行,在wrapper函数中
        return func(self, *args, **kwargs)
      文件 "C:\ProgramData\mambaforge-pypy3\Lib\_sqlite3.py", 第305行,在wrapper函数中
        return func(self, *args, **kwargs)
    TypeError: create_function() 获得意外的关键字参数 'narg'

    在处理上述异常期间,发生了另一个异常:

    回溯(最近的调用最后):
      文件 "C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda\exception_handler.py",
第17行,在__call__函数中
        return func(*args, **kwargs)
      文件 "C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda\cli\main.py",
第64行,在main_subshell函数中
        exit_code = do_call(args, parser)
      文件 "C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda\cli\conda_argparse.py",
第143行,在do_call函数中
        result = plugin_subcommand.action(getattr(args, "_args", args))
      文件 "C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda_build\plugin.py",
第10行,在build函数中
        execute(*args, **kwargs)
      文件 "C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda_build\cli\main_build.py",
第568行,在execute函数中
        outputs = api.build(
      文件 "C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda_build\api.py",
第253行,在build函数中
        return build_tree(
      文件 "C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda_build\build.py",
第3804行,在build_tree函数中
        packages_from_this = build(
      文件 "C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda_build\build.py",
第2474行,在build函数中
        output_metas = expand_outputs([(m, need_source_download, need_reparse_in_env)])
      文件 "C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda_build\render.py",
第923行,在expand_outputs函数中
        for output_dict, m in deepcopy(_m).get_output_metadata_set(
      文件 "C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda_build\metadata.py",
第2574行,在get_output_metadata_set函数中
        conda_packages = finalize_outputs_pass(
      文件 "C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda_build\metadata.py",
第934行,在finalize_outputs_pass函数中
        fm = finalize_metadata(
      文件 "C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda_build\render.py",
第637行,在finalize_metadata函数中
        build_unsat, host_unsat = add_upstream_pins(
      文件 "C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda_build\render.py",
第452行,在add_upstream_pins函数中
        build_deps, build_unsat, extra_run_specs_from_build = _read_upstream_pin_files(
      文件 "C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda_build\render.py",
第431行,在_read_upstream_pin_files函数中
        deps, actions, unsat = get_env_dependencies(
      文件 "C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda_build\render.py",
第151行,在get_env_dependencies函数中
        actions = environ.get_install_actions(
      文件 "C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda_build\environ.py",
第869行,在get_install_actions函数中
        index, index_ts, _ = get_build_index(
      文件 "C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda_build\index.py",
第203行,在get_build_index函数中
        _delegated_update_index(output_folder, verbose=debug)
      文件 "C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda_build\index.py",
第315行,在_delegated_update_index函数中
        return _update_index(
      文件 "C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda_index\index\__init__.py",
第159行,在update_index函数中
        channel_index.index(
      文件 "C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda_index\index\__init__.py",
第562行,在index函数中
        futures = [
      文件 "C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda_index\index\__init__.py",
第562行,在列表推导式中
        futures = [
      文件 "C:\ProgramData\mambaforge-pypy3\Lib\concurrent\futures\_base.py",
第609行,在result_iterator函数中
        yield fs.pop().result()
      文件 "C:\ProgramData\mambaforge-pypy3\Lib\concurrent\futures\_base.py",
第446行,在result函数中
        return self.__get_result()
      文件 "C:\ProgramData\mambaforge-pypy3\Lib\concurrent\futures\_base.py",
第391行,在__get_result函数中
        raise self._exception
      文件 "C:\ProgramData\mambaforge-pypy3\Lib\concurrent\futures\thread.py",
第58行,在run函数中
        result = self.fn(*self.args, **self.kwargs)
      文件 "C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda_index\index\__init__.py",
第550行,在extract_wrapper函数中
        return self.extract_subdir_to_cache(
      文件 "C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda_index\index\__init__.py",
第757行,在extract_subdir_to_cache函数中
        cache.save_fs_state(subdir_path)
      文件 "C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda_index\index\sqlitecache.py",
第451行,在save_fs_state函数中
        with self.db:
      文件 "C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda_index\index\sqlitecache.py",
第76行,在__get__函数中
        value = self.wrapped(inst)
      文件 "C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda_index\index\sqlitecache.py",
第122行,在db函数中
        convert_cache.migrate(conn)
      文件 "C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda_index\index\convert_cache.py",
第135行,在migrate函数中
        remove_prefix(conn)
      文件 "C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda_index\index\convert_cache.py",
第160行,在remove_prefix函数中
        conn.create_function("migrate_basename", narg=1, func=basename)
      文件 "C:\ProgramData\mambaforge-pypy3\Lib\_sqlite3.py", 第324行,在wrapper函数中
        return func(self, *args, **kwargs)
      文件 "C:\ProgramData\mambaforge-pypy3\Lib\_sqlite3.py", 第305行,在wrapper函数中
        return func(self, *args, **kwargs)
    TypeError: create_function() 获得意外的关键字参数 'narg'

`$ C:\ProgramData\mambaforge-pypy3\Scripts\conda-script.py build
binda`

  环境变量:
                 CIO_TEST=<未设置>
    CONDA_ALLOW_SOFTLINKS=false
        CONDA_DEFAULT_ENV=binda
                CONDA_EXE=C:\ProgramData\mambaforge-pypy3\condabin\..\Scripts\conda.exe
               CONDA_EXES="C:\ProgramData\mambaforge-pypy3\condabin\..\Scripts\conda.exe"
             CONDA_PREFIX=C:\Users\jlcas\anaconda3\envs\binda
           CONDA_PREFIX_1=C:\ProgramData\mambaforge-pypy3
    CONDA_PROMPT_MODIFIER=(binda)
         CONDA_PYTHON_EXE=C:\ProgramData\mambaforge-pypy3\python.exe
               CONDA_ROOT=C:\ProgramData\mambaforge-pypy3
              CONDA_SHLVL=2
           CURL_CA_BUNDLE=<未设置>
                 HOMEPATH=\Users\jlcas
               LD_PRELOAD=<未设置>
                     PATH=C:\Users\jlcas\anaconda3\envs\binda;C:\Users\jlcas\anaconda3\envs\bind
                          a\Library\mingw-w64\bin;C:\Users\jlcas\anaconda3\envs\binda\Library\us
                          r\bin;C:\Users\jlcas\anaconda3\envs\binda\Library\bin;C:\Users\jlcas\a
                          naconda3\envs\binda\Scripts;C:\Users\jlcas\anaconda3\envs\binda\bin;C:
                          \ProgramData\mambaforge-pypy3\condabin;C:\ProgramData\mambaforge-
                          pypy3;C:\ProgramData\mambaforge-
                          pypy3\Library\mingw-w64\bin;C:\ProgramData\mambaforge-
                          pypy3\Library\usr\bin;C:\ProgramData\mambaforge-
                          pypy3\Library\bin;C:\ProgramData\mambaforge-pypy3\Scripts;C:\WINDOWS\s
                          ystem32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\Window
                          sPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program
                          Files\Git\cmd;C:\Program Files\010 Editor;C:\Program Files\dotnet;C:\U
                          sers\jlcas\AppData\Local\Microsoft\WindowsApps;.;C:\sdk\flutter\bin;C:
                          \Program Files\Android\Android
                          Studio\jbr\bin;C:\Users\jlcas\AppData\Roaming\TinyTeX\bin\windows
             PSMODULEPATH=C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\Windows
                          PowerShell\v1.0\Modules
               PYTHONPATH={PYTHONPATH};./src;./tests;../src;
       REQUESTS_CA_BUNDLE=<未设置>
            SSL_CERT_FILE=C:\Users\jlcas\anaconda3\envs\binda\Library\ssl\cacert.pem

     激活环境 : C:\Users\jlcas\anaconda3\envs\binda
    激活环境路径 : C:\Users\jlcas\anaconda3\envs\binda
            shell层级 : 2
       用户配置文件 : C:\Users\jlcas\.condarc  已加载的配置文件 : C:\ProgramData\mambaforge-pypy3\.condarc
                          C:\Users\jlcas\.condarc
          conda版本 : 23.7.4
    conda-build版本 : 3.26.1
         python版本 : 3.9.17.final.0
       虚拟包 : __archspec=1=x86_64
                          __cuda=11.2=0
                          __win=0=0
       基础环境 : C:\ProgramData\mambaforge-pypy3  (可写)
      conda av数据目录 : C:\ProgramData\mambaforge-pypy3\etc\conda   conda av元数据URL : None
           频道URL : https://repo.anaconda.com/pkgs/main/win-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/win-64
                          https://repo.anaconda.com/pkgs/r/noarch
                          https://repo.anaconda.com/pkgs/msys2/win-64
                          https://repo.anaconda.com/pkgs/msys2/noarch
                          https://conda.anaconda.org/conda-forge/win-64
                          https://conda.anaconda.org/conda-forge/noarch
          包缓存 : C:\ProgramData\mambaforge-pypy3\pkgs
                          C:\Users\jlcas\.conda\pkgs
                          C:\Users\jlcas\AppData\Local\conda\conda\pkgs
       环境目录 : C:\ProgramData\mambaforge-pypy3\envs
                          C:\Users\jlcas\.conda\envs
                          C:\Users\jlcas\AppData\Local\conda\conda\envs
               平台 : win-64
             用户代理 : conda/23.7.4 requests/2.31.0 PyPy/3.9.17 Windows/10 Windows/10.0.22621
          管理员权限 : False
             netrc文件 : None
           离线模式 : False


发生意外错误。Conda已生成上述报告。
如果怀疑错误由故障插件导致,请考虑使用--no-plugins选项禁用插件。

示例: conda --no-plugins install <包名>

或者,你可以在命令行设置CONDA_NO_PLUGINS环境变量以禁用插件运行命令。

示例: CONDA_NO_PLUGINS=true conda install <包名>

问题原因

该错误源于conda-index库在调用SQLite的create_function时使用了narg关键字参数,但PyPy的_sqlite3实现不支持该参数名——标准CPython的sqlite3.Connection.create_function使用的参数名是num_params,而非narg。

解决方案

方案1:升级conda-index到修复版本

检查是否有修复该参数兼容问题的conda-index版本,执行升级:

conda update conda-index

方案2:临时修改conda-index源代码

找到conda_index/index/convert_cache.py文件(路径对应报错中的C:\ProgramData\mambaforge-pypy3\lib\site-packages\conda_index\index\convert_cache.py),将其中两处narg=1替换为num_params=1:

  • 第158行:conn.create_function("migrate_basename", num_params=1, func=basename, deterministic=True)
  • 第160行:conn.create_function("migrate_basename", num_params=1, func=basename)

修改后保存文件,重新执行conda build。

方案3:切换到CPython环境

由于该问题是PyPy与conda-index的兼容问题,切换到标准CPython环境(而非PyPy)执行conda build即可避免该报错。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 04:27:31