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

如何解决Colab中安装torch==1.6.0及相关依赖的报错问题?

问题:Deep Exemplar Based Video Colorization Colab演示环境配置失败

背景

使用四年的Deep Exemplar Based Video Colorization Colab演示,本周一执行环境配置代码时出现报错,需排查是否由近期更新导致,并寻求解决办法。

原环境配置代码

# seems to be a colab bug, need to install previous version for pytorch
!pip install torch==1.6.0 torchvision==0.7.0
!pip install -q moviepy
!apt install imagemagick
!pip install imageio==2.4.1

%cd Deep-Exemplar-based-Video-Colorization/
! pip install -r requirements.txt

报错信息

ERROR: Could not find a version that satisfies the requirement torch==1.6.0 (from versions: 1.11.0, 1.12.0, 1.12.1, 1.13.0, 1.13.1, 2.0.0, 2.0.1, 2.1.0, 2.1.1, 2.1.2, 2.2.0, 2.2.1, 2.2.2, 2.3.0, 2.3.1, 2.4.0, 2.4.1, 2.5.0)
ERROR: No matching distribution found for torch==1.6.0

--------------------------------
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
moviepy 1.0.3 requires imageio<3.0,>=2.5; python_version >= "3.4", but you have imageio 2.4.1 which is incompatible.
scikit-image 0.24.0 requires imageio>=2.33, but you have imageio 2.4.1 which is incompatible.

------------------------------------------------
ERROR: Failed building wheel for scipy
  Running setup.py clean for scipy
  error: subprocess-exited-with-error
  
  × python setup.py clean 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.
  ERROR: Failed cleaning build dir for scipy
---------------------------------------------

原因分析

  1. PyTorch 1.6.0已被pip源移除:Colab近期更新了Python运行环境(当前为3.10+),而PyTorch 1.6.0仅支持Python 3.6-3.8,pip官方源已不再提供该版本的适配包,导致安装失败。
  2. 依赖版本冲突:强制安装的imageio 2.4.1版本过低,与moviepy、scikit-image的最低版本要求不兼容,触发依赖冲突提示。
  3. scipy构建失败:项目requirements.txt中指定的scipy版本过旧,与当前Colab环境的编译工具链不兼容,导致wheel构建失败。

解决办法

调整环境配置代码,使用兼容当前Colab环境的依赖版本:

修改后的配置代码

# 安装兼容Colab当前Python版本的PyTorch旧版本
!pip install torch==1.13.1 torchvision==0.14.1 --index-url https://download.pytorch.org/whl/cu116
!pip install -q moviepy==1.0.3
!apt install imagemagick
# 安装满足所有依赖的imageio版本
!pip install imageio==2.33.1

%cd Deep-Exemplar-based-Video-Colorization/
# 忽略已存在的依赖冲突,强制安装项目依赖
!pip install -r requirements.txt --ignore-installed scipy
# 单独安装兼容的scipy版本
!pip install scipy==1.10.1

说明

  • 选择PyTorch 1.13.1是因为它支持Python 3.10,且与原项目代码兼容性较好;--index-url指定CUDA 11.6的源,匹配Colab当前的GPU环境。
  • imageio 2.33.1同时满足moviepy(<3.0,>=2.5)和scikit-image(>=2.33)的版本要求,解决依赖冲突。
  • 安装项目依赖时忽略已安装的scipy,再单独安装兼容的scipy 1.10.1,避免构建失败。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 21:02:42