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

安装PyYAML==5.4.1时触发subprocess-exited-with-error错误求助

PyYAML==5.4.1安装报错(AttributeError: cython_sources)解决方案

安装PyYAML==5.4.1(来自/xxx/src/requirements_2.txt第21行)时触发subprocess-exited-with-error错误,核心报错为AttributeError: cython_sources,完整报错信息如下:

Collecting PyYAML==5.4.1 (from -r /xxx/src/requirements_2.txt (line 21))
  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
  ╰─> [48 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 "/xxx/env/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/xxx/env/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/xxx/env/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
        File "/private/var/folders/c7/59xfc0ns6r9bz5h8lnhz0b140000gn/T/pip-build-env-k3l_7j20/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 332, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=[])
        File "/private/var/folders/c7/59xfc0ns6r9bz5h8lnhz0b140000gn/T/pip-build-env-k3l_7j20/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 302, in _get_build_requires
          self.run_setup()
        File "/private/var/folders/c7/59xfc0ns6r9bz5h8lnhz0b140000gn/T/pip-build-env-k3l_7j20/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 318, in run_setup
          exec(code, locals())
        File "<string>", line 271, in <module>
        File "/private/var/folders/c7/59xfc0ns6r9bz5h8lnhz0b140000gn/T/pip-build-env-k3l_7j20/overlay/lib/python3.9/site-packages/setuptools/__init__.py", line 117, in setup
          return distutils.core.setup(**attrs)
        File "/private/var/folders/c7/59xfc0ns6r9bz5h8lnhz0b140000gn/T/pip-build-env-k3l_7j20/overlay/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 184, in setup
          return run_commands(dist)
        File "/private/var/folders/c7/59xfc0ns6r9bz5h8lnhz0b140000gn/T/pip-build-env-k3l_7j20/overlay/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 200, in run_commands
          dist.run_commands()
        File "/private/var/folders/c7/59xfc0ns6r9bz5h8lnhz0b140000gn/T/pip-build-env-k3l_7j20/overlay/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 954, in run_commands
          self.run_command(cmd)
        File "/private/var/folders/c7/59xfc0ns6r9bz5h8lnhz0b140000gn/T/pip-build-env-k3l_7j20/overlay/lib/python3.9/site-packages/setuptools/dist.py", line 950, in run_command
          super().run_command(command)
        File "/private/var/folders/c7/59xfc0ns6r9bz5h8lnhz0b140000gn/T/pip-build-env-k3l_7j20/overlay/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 973, in run_command
          cmd_obj.run()
        File "/private/var/folders/c7/59xfc0ns6r9bz5h8lnhz0b140000gn/T/pip-build-env-k3l_7j20/overlay/lib/python3.9/site-packages/setuptools/command/egg_info.py", line 311, in run
          self.find_sources()
        File "/private/var/folders/c7/59xfc0ns6r9bz5h8lnhz0b140000gn/T/pip-build-env-k3l_7j20/overlay/lib/python3.9/site-packages/setuptools/command/egg_info.py", line 319, in find_sources
          mm.run()
        File "/private/var/folders/c7/59xfc0ns6r9bz5h8lnhz0b140000gn/T/pip-build-env-k3l_7j20/overlay/lib/python3.9/site-packages/setuptools/command/egg_info.py", line 540, in run
          self.add_defaults()
        File "/private/var/folders/c7/59xfc0ns6r9bz5h8lnhz0b140000gn/T/pip-build-env-k3l_7j20/overlay/lib/python3.9/site-packages/setuptools/command/egg_info.py", line 578, in add_defaults
          sdist.add_defaults(self)
        File "/private/var/folders/c7/59xfc0ns6r9bz5h8lnhz0b140000gn/T/pip-build-env-k3l_7j20/overlay/lib/python3.9/site-packages/setuptools/command/sdist.py", line 108, in add_defaults
          super().add_defaults()
        File "/private/var/folders/c7/59xfc0ns6r9bz5h8lnhz0b140000gn/T/pip-build-env-k3l_7j20/overlay/lib/python3.9/site-packages/setuptools/_distutils/command/sdist.py", line 250, in add_defaults
          self._add_defaults_ext()
        File "/private/var/folders/c7/59xfc0ns6r9bz5h8lnhz0b140000gn/T/pip-build-env-k3l_7j20/overlay/lib/python3.9/site-packages/setuptools/_distutils/command/sdist.py", line 335, in _add_defaults_ext
          self.filelist.extend(build_ext.get_source_files())
        File "<string>", line 201, in get_source_files
        File "/private/var/folders/c7/59xfc0ns6r9bz5h8lnhz0b140000gn/T/pip-build-env-k3l_7j20/overlay/lib/python3.9/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.

解决方法

  • 预安装Cython依赖
    PyYAML 5.4.1的源码编译依赖Cython,先安装Cython再执行安装命令:

    pip install cython
    pip install PyYAML==5.4.1
    

    或合并为单条命令:

    pip install cython PyYAML==5.4.1
    
  • 使用预编译wheel包
    跳过源码编译,强制下载预编译的wheel文件:

    pip install PyYAML==5.4.1 --only-binary :all:
    
  • 降级setuptools版本
    新版本setuptools与PyYAML 5.4.1的旧构建逻辑不兼容,降级到稳定版本:

    pip install setuptools==58.0.4
    pip install PyYAML==5.4.1
    
  • 更换PyYAML版本
    若上述方案无效,可升级到修复了编译问题的版本,比如PyYAML==5.4.2:

    pip install PyYAML==5.4.2
    

    或修改requirements_2.txt中的版本号后重新安装。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 12:29:49