Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RuntimeError: Error compiling objects for extension while installing detectron2

I’m trying to install detectron2 on my local machine. A cpp_extension.py located in

C:\Users\Username\miniconda3\envs\pytorch_env\lib\site-packages\torch\utils\cpp_extension.py

fails to compile and throws a

raise RuntimeError(message) from e RuntimeError: Error compiling objects for extension

I just finished installing the tensorflow object detection API so I have pycocotools and other c++ build tools required. Are there more extensions of c++ tools I would have to install?

  • OS: windows 10, no GPU

  • Visual Studio tools installed: 2015 and 2019 build tools, windows 10 sdk, windows universal crt and crt sdk

  • pytorch version: 1.12.1

command leading to error:

python -m pip install -e detectron2
like image 766
Sillette Avatar asked Sep 11 '25 13:09

Sillette


2 Answers

I was facing the same error which i was able to solve after spending 1 whole day.

The below mentioned are my configurations in ubuntu machine:

Python version: 3.11.0rc1
Torch version: 2.1.0+cu118
TorchVision version: 0.16.0+cu118
TorchAudio version: 2.1.0+cu118
Detectron2 version: 0.6

And I installed detectron2 by running the following command:

pip install -e git+https://github.com/facebookresearch/detectron2.git@864913f0e57e87a75c8cc0c7d79ecbd774fc669b#egg=detectron2

For me the file

C:\Users\Username\miniconda3\envs\pytorch_env\lib\site-packages\torch\utils\cpp_extension.py

was failing to compile and throwing this error as well

raise RuntimeError(message) from e RuntimeError: Error compiling objects for extension

I solved it by running this command

sudo apt-get install python3.11-dev

Make sure gcc & g++ are correctly setup

like image 81
Anonymous Avatar answered Sep 14 '25 20:09

Anonymous


You can look into this raised GitHub issue:

https://github.com/facebookresearch/maskrcnn-benchmark/issues/1236

It most likely is a Pytorch version(compatibility) problem.

like image 45
barvin04 Avatar answered Sep 14 '25 21:09

barvin04