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

Docker环境下使用Poetry时PyTorch与torchvision疑似兼容问题

问题:Docker中使用Poetry管理依赖时PyTorch与Torchvision加载自定义C++ Ops失败

我尝试在Docker中用Poetry运行项目,该项目在Windows和Linux系统的Poetry虚拟环境中可正常运行,但在Docker环境执行时出现以下错误:

RuntimeError: Couldn't load custom C++ ops. This can happen if your PyTorch and torchvision versions are incompatible, or if you had errors while compiling torchvision from source. For further information on the compatible versions, check the official compatibility matrix of PyTorch Vision. Please check your PyTorch version with torch.__version__ and your torchvision version with torchvision.__version__ and verify if they are compatible, and if not please reinstall torchvision so that it matches your PyTorch install.

用虚拟环境的pip重新安装torchvision能解决问题,但我希望仅通过Poetry完成依赖管理。该问题在Linux Docker和Windows(WSL2)Docker环境中均会出现,非Docker环境下程序运行正常。

根据Torchvision的安装说明,当前PyTorch和Torchvision版本是兼容的,具体版本信息如下:

root@eb8f096b3563:/app# poetry run pip show torch
Name: torch
Version: 2.1.2+cpu
Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration
Home-page: https://pytorch.org/
Author: PyTorch Team
Author-email: packages@pytorch.org
License: BSD-3
Location: /root/.cache/pypoetry/virtualenvs/wyzely-detect-9TtSrW0h-py3.10/lib/python3.10/site-packages
Requires: filelock, fsspec, jinja2, networkx, sympy, typing-extensions
Required-by: thop, torchvision, ultralytics, wyzely-detect
root@eb8f096b3563:/app# poetry run pip show torchvision
Name: torchvision
Version: 0.16.2
Summary: image and video datasets and models for torch deep learning
Home-page: https://github.com/pytorch/vision
Author: PyTorch Core Team
Author-email: soumith@pytorch.org
License: BSD
Location: /root/.cache/pypoetry/virtualenvs/wyzely-detect-9TtSrW0h-py3.10/lib/python3.10/site-packages
Requires: numpy, pillow, requests, torch
Required-by: ultralytics
root@eb8f096b3563:/app# 

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 12:57:32