#983 Invalid requirement: 'torch~=2.7.1+cu128': Local version label can only be used with `==` or `!=` operators torch~=2

2409:8a70* Posted at: 21 hours ago 👁12

image

1 Replies

本条内容由 gpt-5-mini 回复
错误原因:requirements.txt 中把带有本地版本标签(+cu128)的 torch 与兼容运算符 ~= 一起使用了。根据 PEP 440,带有本地版本标识(如 +cu128)的版本只能与 == 或 != 一起使用,所以 pip 报错 “Local version label can only be used with == or != operators”。

解决方案(任选其一):

1) 推荐(修改 requirements 文件)

1. 打开项目根目录下的 requirements.txt,把第 27 行

torch~=2.7.1+cu128

改为

torch==2.7.1+cu128

2. 重新安装:

pip install -r requirements.txt

说明:用 == 指定本地版本标签是合法的,但 pip 需要能从指定源找到对应的 wheel(通常需 PyTorch 官方的 CUDA wheel 源)。

2) 如果 pip 找不到 +cu128 的 wheel(常见情况),直接从 PyTorch 官方索引安装 CUDA 版本:

pip install --index-url https://download.pytorch.org/whl/cu128 torch==2.7.1+cu128

(如需 torchvision/torchaudio,按官方说明一并指定版本并从同一索引安装)

3) 不需要 CUDA(或想让 pip 选择可用的通用包)

  • 将 requirements.txt 中改为不带本地标签的兼容写法,例如:

torch~=2.7.1

然后 pip install -r requirements.txt

说明:这样可能会安装 CPU 版本或与系统 CUDA 不匹配的版本,按需选择。

4) 如果你使用的是 Windows 预打包版

  • 预打包版已绑定 torch2.7.1+cu128,通常无需手动 pip 安装 torch。建议直接使用 sp.exe 的预打包环境,避免自行 pip 全量安装导致依赖冲突。

补充说明:

  • 原因本质是版本规范不合法(PEP 440 限制),改用 == 即可解决语法报错,但是否能成功安装还取决于 pip 是否能从指定索引找到对应 wheel。
  • 若按上述方法仍无法安装,请提供位于 videotrans/logs/ 目录下的最新日志文件或粘贴 pip 的完整错误输出以便进一步诊断。
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.

Donate: https://ko-fi.com/jianchang512

Trending Questions