#3095 执行uv sync报错error: Distribution torch==2.7.1 @ registry+https://download.pytorch.org/whl/cpu can't be installed because i

220.246* Posted at: 7 hours ago 👁11

执行uv sync报错error: Distribution torch==2.7.1 @ registry+https://download.pytorch.org/whl/cpu can't be installed because it doesn't have a source distribution or wheel for the current platform

hint: You're on macOS (macosx_14_0_x86_64), but torch (v2.7.1) only has wheels for the following platform: macosx_11_0_arm64; consider adding "sys_platform == 'darwin' and platform_machine == 'x86_64'" to tool.uv.required-environments to ensure uv resolves to a version with compatible wheels

1 Replies

这是由于在 macOS x86_64 架构的机器上,uv 包管理器尝试安装的 PyTorch 2.7.1 版本仅提供了适用于 Apple Silicon (arm64) 的预编译包,没有为 Intel (x86_64) 架构提供。

解决方案

  1. 修改 pyproject.toml 文件:在 pyVideoTrans 项目根目录下,找到 pyproject.toml 文件。
  2. 添加平台约束:在文件中找到 [tool.uv][project] 部分,根据错误提示,添加以下行来指定 PyTorch 的安装源,确保为 x86_64 平台获取正确的版本:

    [tool.uv]
    required-environments = ["sys_platform == 'darwin' and platform_machine == 'x86_64'"]

    或者,更直接地,可以指定一个兼容的 PyTorch 版本。在 [project]dependencies 部分,将 torch 的版本约束修改为明确支持 macOS x86_64 的版本,例如:

    dependencies = [
        ... # 其他依赖
        "torch>=2.0.0,<2.8.0; sys_platform == 'darwin' and platform_machine == 'x86_64'",
    ]

    如果项目使用 uv.lock,你可能需要先删除 uv.lock 文件,再重新运行 uv sync

  3. 重新同步依赖:保存 pyproject.toml 文件后,在终端中重新执行 uv sync 命令。
  4. 备选方案:如果上述方法无效,可以尝试手动安装一个兼容的 PyTorch 版本。访问 PyTorch 官网,选择适合 macOS x86_64 的安装命令(例如使用 pip 安装 CPU 版本),手动安装后再运行 uv sync

注意:由于 macOS x86_64 架构已逐渐被 Apple Silicon 取代,部分 AI 库的预编译包支持可能有限。如果遇到其他类似问题,可能需要寻找为 x86_64 架构编译的替代版本或从源码编译。

请查阅相关文档:

Post Your Reply
Open source and free maintenance is not easy. If this project is helpful to you, please consider making a small donation to help the project continue to maintain and update.

Related resource