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

Anaconda虚拟环境安装OpenAI SpinningUp遇torch版本匹配问题求助

解决OpenAI SpinningUp安装时torch==1.3.1版本找不到的问题

我在跟着OpenAI SpinningUp教程搭建环境时,也碰到过一模一样的问题,给你几个靠谱的解决思路:

问题背景

执行pip install -e .时触发版本匹配错误,终端输出如下:

ERROR: Could not find a version that satisfies the requirement torch==1.3.1 (from spinup==0.2.0) (from versions: 0.1.2, 0.1.2.post1, 0.1.2.post2)
ERROR: No matching distribution found for torch==1.3.1 (from spinup==0.2.0)

你的requirements.txt确实没列torch,但SpinningUp的部分算法模块(比如基于PyTorch实现的PPO、DDPG等)是隐式依赖torch的,这个要求写在了项目的setup.py里。而Windows默认的PyPI源没有索引到旧版本的torch轮子,才会出现找不到版本的报错。

解决方案

1. 手动指定PyTorch官方源安装对应版本

这是最稳妥的方法,根据你的环境选择对应命令:

  • 如果用CPU版本(你的环境里CUDA版本是10.2,而torch1.3.1仅支持到CUDA10.1,优先推荐CPU版):
    pip install torch==1.3.1+cpu -f https://download.pytorch.org/whl/torch_stable.html
    
  • 如果你的环境兼容CUDA10.1,可以安装GPU版:
    pip install torch==1.3.1+cu101 -f https://download.pytorch.org/whl/torch_stable.html
    

安装完成后重新执行pip install -e .,就能正常完成依赖安装了。

2. 调整setup.py的依赖限制(可选)

如果不想严格安装1.3.1版本,可以找到项目根目录的setup.py,把里面的torch==1.3.1改成torch>=1.3.0,让pip自动匹配兼容的最新版本。不过这个方法有一定风险——部分算法的实现可能依赖特定版本的torch特性,所以优先推荐第一种方案。

3. 统一torch与torchvision版本

你的环境里已经装了torchvision==0.2.2,这个版本对应torch1.1.0左右,和要求的1.3.1不兼容,建议先卸载现有包:

pip uninstall torch torchvision -y

然后安装匹配版本的torch和torchvision:

pip install torch==1.3.1+cpu torchvision==0.4.2+cpu -f https://download.pytorch.org/whl/torch_stable.html

补充说明

这个问题本质是PyTorch早期版本的Windows轮子没有上传到默认PyPI源,必须指定官方的whl源才能找到,算是旧版本PyTorch在Windows环境下的常见安装坑。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.07 17:22:48