Ubuntu22.04-Cuda12.1 安装 Detectron2
#碎碎念------------------------>环境python3.10 - Cuda12.1
帮同学配置环境,这个detectron2停更好几年了,配置起来有些折磨人。Detectron2项目地址
我用的是Ubuntu2204+cuda12.1的环境,最开始一直想着用编译好的环境,不想自己去动手,下来下去给我40g流量下没了,问题还是解决不了,参考Issue、别人的环境怎么做的、最后结合着Gemini 2.5pro、Claude给出的建议成功把detectron2给编译了出来,还是要夸一下Claude,感觉这种问题,它比Gemini、Chatgpt都要厉害些。
#直接进入正题-----pytorch版本和cuda需要对应,链接
conda create -n detectron-env python=3.10 -y
conda activate detectron-env
conda install pytorch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 pytorch-cuda=12.1 -c pytorch -c nvidia
git clone https://github.com/facebookresearch/detectron2.git
cd detectron2
#接下来问题就出现了----若直接运行无误恭喜你可以离开了
python -m pip install -e
#如果安装到[35/36]报错,恭喜你---解决答案要接近了
#解决方式A.前提pytorch和cuda版本对应(建议)
pip install --no-build-isolation --use-pep517 -e .
#解决方式B.
在detectron2所在文件夹下创建pyproject.toml,内容为
[build-system]
requires = ["setuptools>=42", "wheel", "torch>=1.8"]
build-backend = "setuptools.build_meta"
然后执行,具体是不是这个我有点忘记了。。。
python -m pip install -e .