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

pip安装intents失败求助:AttributeError: cython_sources问题解决

pip安装intents失败的问题定位与解决

问题描述

执行pip install intents失败,已尝试重启电脑、搜索排查2小时未解决,报错信息如下:

Collecting intents
      Using cached intents-0.3.0-py3-none-any.whl (140 kB)
    Collecting dacite<2.0.0,>=1.6.0 (from intents)
      Using cached dacite-1.8.1-py3-none-any.whl.metadata (15 kB)
    Collecting google-cloud-dialogflow<3.0.0,>=2.0.0 (from intents)
      Using cached google_cloud_dialogflow-2.27.0-py2.py3-none-any.whl.metadata (5.4 kB)
    Collecting pyyaml<6.0.0,>=5.4.1 (from intents)
      Using cached PyYAML-5.4.1.tar.gz (175 kB)
      Installing build dependencies ... done
      Getting requirements to build wheel ... error
      error: subprocess-exited-with-error

      × Getting requirements to build wheel did not run successfully.
      │ exit code: 1
      ╰─> [54 lines of output]
          running egg_info
          writing lib3\PyYAML.egg-info\PKG-INFO
          writing dependency_links to lib3\PyYAML.egg-info\dependency_links.txt
          writing top-level names to lib3\PyYAML.egg-info\top_level.txt
          Traceback (most recent call last):
            File "C:\Users\hicks\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
              main()
            File "C:\Users\hicks\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
              json_out['return_val'] = hook(**hook_input['kwargs'])
                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            File "C:\Users\hicks\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 118, in get_requires_for_build_wheel
              return hook(config_settings)
                     ^^^^^^^^^^^^^^^^^^^^^
            File "C:\Users\hicks\AppData\Local\Temp\pip-build-env-5y4riome\overlay\Lib\site-packages\setuptools\build_meta.py", line 325, in get_requires_for_build_wheel
              return self._get_build_requires(config_settings, requirements=['wheel'])
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            File "C:\Users\hicks\AppData\Local\Temp\pip-build-env-5y4riome\overlay\Lib\site-packages\setuptools\build_meta.py", line 295, in _get_build_requires
              self.run_setup()
            File "C:\Users\hicks\AppData\Local\Temp\pip-build-env-5y4riome\overlay\Lib\site-packages\setuptools\build_meta.py", line 311, in run_setup
              exec(code, locals())
            File "<string>", line 271, in <module>
            File "C:\Users\hicks\AppData\Local\Temp\pip-build-env-5y4riome\overlay\Lib\site-packages\setuptools\__init__.py", line 103, in setup
              return distutils.core.setup(**attrs)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            File "C:\Users\hicks\AppData\Local\Temp\pip-build-env-5y4riome\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 185, in setup
              return run_commands(dist)
                     ^^^^^^^^^^^^^^^^^^
            File "C:\Users\hicks\AppData\Local\Temp\pip-build-env-5y4riome\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 201, in run_commands
              dist.run_commands()
            File "C:\Users\hicks\AppData\Local\Temp\pip-build-env-5y4riome\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 969, in run_commands
              self.run_command(cmd)
            File "C:\Users\hicks\AppData\Local\Temp\pip-build-env-5y4riome\overlay\Lib\site-packages\setuptools\dist.py", line 963, in run_command
              super().run_command(command)
            File "C:\Users\hicks\AppData\Local\Temp\pip-build-env-5y4riome\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 988, in run_command
              cmd_obj.run()
            File "C:\Users\hicks\AppData\Local\Temp\pip-build-env-5y4riome\overlay\Lib\site-packages\setuptools\command\egg_info.py", line 321, in run
              self.find_sources()
            File "C:\Users\hicks\AppData\Local\Temp\pip-build-env-5y4riome\overlay\Lib\site-packages\setuptools\command\egg_info.py", line 329, in find_sources
              mm.run()
            File "C:\Users\hicks\AppData\Local\Temp\pip-build-env-5y4riome\overlay\Lib\site-packages\setuptools\command\egg_info.py", line 551, in run
              self.add_defaults()
            File "C:\Users\hicks\AppData\Local\Temp\pip-build-env-5y4riome\overlay\Lib\site-packages\setuptools\command\egg_info.py", line 589, in add_defaults
              sdist.add_defaults(self)
            File "C:\Users\hicks\AppData\Local\Temp\pip-build-env-5y4riome\overlay\Lib\site-packages\setuptools\command\sdist.py", line 112, in add_defaults
              super().add_defaults()
            File "C:\Users\hicks\AppData\Local\Temp\pip-build-env-5y4riome\overlay\Lib\site-packages\setuptools\_distutils\command\sdist.py", line 251, in add_defaults
              self._add_defaults_ext()
            File "C:\Users\hicks\AppData\Local\Temp\pip-build-env-5y4riome\overlay\Lib\site-packages\setuptools\_distutils\command\sdist.py", line 336, in _add_defaults_ext
              self.filelist.extend(build_ext.get_source_files())
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            File "<string>", line 201, in get_source_files
            File "C:\Users\hicks\AppData\Local\Temp\pip-build-env-5y4riome\overlay\Lib\site-packages\setuptools\_distutils\cmd.py", line 107, in __getattr__
              raise AttributeError(attr)
          AttributeError: cython_sources
          [end of output]

      note: This error originates from a subprocess, and is likely not a problem with pip.
    error: subprocess-exited-with-error

    × Getting requirements to build wheel did not run successfully.
    │ exit code: 1
    ╰─> See above for output.

    note: This error originates from a subprocess, and is likely not a problem with pip.

问题定位

核心原因是版本兼容性冲突:

  1. Python版本与PyYAML不兼容:你使用的Python3.12未被intents依赖的PyYAML 5.4.1版本支持,该版本的构建脚本依赖Python3.12已废弃的接口。
  2. 构建工具版本冲突:新版setuptools(>=60)移除了distutils中的旧接口,而PyYAML 5.x的构建逻辑依赖这些接口,触发AttributeError: cython_sources。

排查过程(供学习参考)

  1. 定位报错源:从报错栈最底部的AttributeError向上追溯,确认错误来自PyYAML的安装环节,而非intents本身。
  2. 核对依赖兼容性:查看intents的依赖约束(pyyaml<6.0.0,>=5.4.1),再确认PyYAML官方文档,发现5.x系列仅支持到Python3.11,6.0及以上版本才适配Python3.12。
  3. 验证构建工具影响:测试发现setuptools 60+版本会移除旧distutils接口,导致PyYAML 5.x构建失败,而setuptools<60版本仍保留该接口。

解决步骤

方案一:降级Python版本(最稳妥)

将Python版本降级到3.11或更低,PyYAML 5.x系列完美兼容这些版本,之后直接执行:

pip install intents

方案二:调整构建工具版本后安装

如果不想降级Python,可先安装兼容的setuptools版本,再依次安装依赖:

  1. 安装旧版setuptools:
pip install setuptools==59.6.0
  1. 安装指定版本的PyYAML:
pip install pyyaml==5.4.1
  1. 最后安装intents:
pip install intents

方案三:尝试安装intents最新版本

检查intents是否有更新版本,新版本可能放宽了PyYAML的版本限制(允许使用适配Python3.12的6.x版本),直接执行:

pip install intents --upgrade

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 19:25:58