Detectron2: ImportError: cannot import name '_C' from 'detectron2'

Created on 11 Nov 2019  路  2Comments  路  Source: facebookresearch/detectron2

I installed detectron2 apparently without problems in Ubuntu 18.04.02 Server Edition

(base) marco@pc:~$ git clone https://github.com/facebookresearch/detectron2.git
Cloning into 'detectron2'...
remote: Enumerating objects: 25, done.
remote: Counting objects: 100% (25/25), done.
remote: Compressing objects: 100% (19/19), done.
remote: Total 1264 (delta 6), reused 12 (delta 6), pack-reused 1239
Receiving objects: 100% (1264/1264), 1.61 MiB | 3.25 MiB/s, done.
Resolving deltas: 100% (726/726), done.
(base) marco@pc:~$ cd detectron2/

(base) marco@pc:~/detectron2$ pip3 install .
Processing /home/marco/detectron2
Requirement already satisfied: termcolor>=1.1 in /home/marco/anaconda3/lib/python3.7/site-
packages (from detectron2==0.1) (1.1.0)
Requirement already satisfied: Pillow in /home/marco/anaconda3/lib/python3.7/site-packages (from 
detectron2==0.1) (6.2.1)
Collecting yacs>=0.1.6
  Downloading https://files.pythonhosted.org/packages/2f/51 
/9d613d67a8561a0cdf696c3909870f157ed85617fea3cff769bb7de09ef7/yacs-0.1.6-py3-none-any.whl
Collecting tabulate
  Downloading https://files.pythonhosted.org/packages/66/d4
/977fdd5186b7cdbb7c43a7aac7c5e4e0337a84cb802e154616f3cfc84563/tabulate-0.8.5.tar.gz (45kB)
     |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 51kB 5.7MB/s 
Collecting cloudpickle
  Using cached https://files.pythonhosted.org/packages/c1/49
/334e279caa3231255725c8e860fa93e72083567625573421db8875846c14/cloudpickle-1.2.2-py2.py3-
none-any.whl
Collecting matplotlib
  Using cached https://files.pythonhosted.org/packages/19/7a
/60bd79c5d79559150f8bba866dd7d434f0a170312e4d15e8aefa5faba294/matplotlib-3.1.1-cp37-
cp37m-manylinux1_x86_64.whl
Requirement already satisfied: tqdm>4.29.0 in /home/marco/anaconda3/lib/python3.7/site-packages 
(from detectron2==0.1) (4.36.1)
Requirement already satisfied: tensorboard in /home/marco/anaconda3/lib/python3.7/site-packages 
(from detectron2==0.1) (1.14.0)
Collecting fvcore@ git+https://github.com/facebookresearch/fvcore.git
  Cloning https://github.com/facebookresearch/fvcore.git to /tmp/pip-install-6m3p_xjr/fvcore
  Running command git clone -q https://github.com/facebookresearch/fvcore.git /tmp/pip-install-
6m3p_xjr/fvcore
Requirement already satisfied: PyYAML in /home/marco/anaconda3/lib/python3.7/site-packages 
(from yacs>=0.1.6->detectron2==0.1) (5.1.1)
Collecting cycler>=0.10
  Using cached https://files.pythonhosted.org/packages/f7/d2
/e07d3ebb2bd7af696440ce7e754c59dd546ffe1bbe732c8ab68b9c834e61/cycler-0.10.0-py2.py3-none-
any.whl
Requirement already satisfied: python-dateutil>=2.1 in /home/marco/anaconda3/lib/python3.7/site-
packages (from matplotlib->detectron2==0.1) (2.8.1)
Collecting kiwisolver>=1.0.1
  Using cached https://files.pythonhosted.org/packages/93/f8
/518fb0bb89860eea6ff1b96483fbd9236d5ee991485d0f3eceff1770f654/kiwisolver-1.1.0-cp37-cp37m-  
 manylinux1_x86_64.whl
Requirement already satisfied: numpy>=1.11 in /home/marco/anaconda3/lib/python3.7/site-packages 
(from matplotlib->detectron2==0.1) (1.17.3)
Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1
  Downloading https://files.pythonhosted.org/packages/c0/0c
/fc2e007d9a992d997f04a80125b0f183da7fb554f1de701bbb70a8e7d479/pyparsing-2.4.5-py2.py3-
none-any.whl (67kB)
     |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 71kB 4.6MB/s 
Collecting werkzeug>=0.11.15
  Downloading https://files.pythonhosted.org/packages/ce/42
/3aeda98f96e85fd26180534d36570e4d18108d62ae36f87694b476b83d6f/Werkzeug-0.16.0-py2.py3-
none-any.whl (327kB)
     |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 327kB 8.6MB/s 
Requirement already satisfied: setuptools>=41.0.0 in /home/marco/anaconda3/lib/python3.7/site-
packages (from tensorboard->detectron2==0.1) (41.0.1)
Requirement already satisfied: six>=1.10.0 in /home/marco/anaconda3/lib/python3.7/site-packages 
(from tensorboard->detectron2==0.1) (1.13.0)
Requirement already satisfied: wheel>=0.26; python_version >= "3" in /home/marco/anaconda3
/lib/python3.7/site-packages (from tensorboard->detectron2==0.1) (0.33.6)
Requirement already satisfied: protobuf>=3.6.0 in /home/marco/anaconda3/lib/python3.7/site-
packages (from tensorboard->detectron2==0.1) (3.9.1)
Requirement already satisfied: grpcio>=1.6.3 in /home/marco/anaconda3/lib/python3.7/site-packages 
(from tensorboard->detectron2==0.1) (1.23.0)
Requirement already satisfied: markdown>=2.6.8 in /home/marco/anaconda3/lib/python3.7/site-
packages (from tensorboard->detectron2==0.1) (3.1.1)
Requirement already satisfied: absl-py>=0.4 in /home/marco/anaconda3/lib/python3.7/site-packages 
(from tensorboard->detectron2==0.1) (0.8.0)
Collecting portalocker
  Downloading https://files.pythonhosted.org/packages/60/ec
/836a494dbaa72541f691ec4e66f29fdc8db9bcc7f49e1c2d457ba13ced42/portalocker-1.5.1-py2.py3-
none-any.whl
Building wheels for collected packages: detectron2, tabulate, fvcore
  Building wheel for detectron2 (setup.py) ... done
  Created wheel for detectron2: filename=detectron2-0.1-cp37-cp37m-linux_x86_64.whl 
size=4362859 sha256=11412710a0ad741950731bea29a690cd2befabce71a3897932f3e5f0c5ecf74d
  Stored in directory: /tmp/pip-ephem-wheel-cache-ewpyenxq/wheels/c1/7c
/12/c54a808b1255ffb2c8e73cca24da506f3f21cc059977a3d554
  Building wheel for tabulate (setup.py) ... done
  Created wheel for tabulate: filename=tabulate-0.8.5-cp37-none-any.whl size=23257   
sha256=1d566341c22374d8709e3b2755da72a8907da2fb842f96910a11a870f164a5f2
  Stored in directory: /home/marco/.cache/pip/wheels/e1/41/ 
5e/e201f95d90fc84f93aa629b6638adacda680fe63aac47174ab
  Building wheel for fvcore (setup.py) ... done
  Created wheel for fvcore: filename=fvcore-0.1-cp37-none-any.whl size=47494 
sha256=b52979152cf49a9ae1c4ea6d8111b573be01d10d7a4e9a7055d5e6d84b71f02d
  Stored in directory: /tmp/pip-ephem-wheel-cache-ewpyenxq/wheels/48/53
/79/3c6485543a4455a0006f5db590ab9957622b6227011941de06
Successfully built detectron2 tabulate fvcore
Installing collected packages: yacs, tabulate, cloudpickle, cycler, kiwisolver, pyparsing, matplotlib, 
portalocker, fvcore, detectron2, werkzeug
Successfully installed cloudpickle-1.2.2 cycler-0.10.0 detectron2-0.1 fvcore-0.1 kiwisolver-1.1.0 
matplotlib-3.1.1 portalocker-1.5.1 pyparsing-2.4.5 tabulate-0.8.5 werkzeug-0.16.0 yacs-0.1.6
(base) marco@pc:~/detectron2$

but when trying to run a demo, it says ' ImportError: cannot import name '_C' from 'detectron2' (/home/marco/detectron2/detectron2/__init__.py)' :

(base) marco@pc:~/detectron2$ python3 demo/demo.py --config-file 
demo/keypoint_rcnn_R_50_FPN_3x.yaml \
> --input demo/federico-fellini-9292860-1-402.jpg \
> --opts MODEL.DEVICE cpu MODEL.WEIGHTS demo/model_final_a6e10b.pkl
Traceback (most recent call last):
  File "demo/demo.py", line 11, in <module>
    from detectron2.data.detection_utils import read_image
  File "/home/marco/detectron2/detectron2/data/__init__.py", line 4, in <module>
    from .build import (
  File "/home/marco/detectron2/detectron2/data/build.py", line 13, in <module>
    from detectron2.structures import BoxMode
  File "/home/marco/detectron2/detectron2/structures/__init__.py", line 2, in <module>
    from .boxes import Boxes, BoxMode, pairwise_iou
  File "/home/marco/detectron2/detectron2/structures/boxes.py", line 7, in <module>
    from detectron2.layers import cat
  File "/home/marco/detectron2/detectron2/layers/__init__.py", line 3, in <module>
    from .deform_conv import DeformConv, ModulatedDeformConv
  File "/home/marco/detectron2/detectron2/layers/deform_conv.py", line 10, in <module>
    from detectron2 import _C
ImportError: cannot import name '_C' from 'detectron2' (/home/marco/detectron2/detectron2 
/__init__.py)

How to solve the problrm?
Marco

Most helpful comment

(base) marco@pc:~/detectron2$ python3 demo/demo.py --config-file

when you run python in the "detectron2" directory, it will use detectron2 that's in that directory, which is not compiled. It will not use the correct detectron2 that you installed to the system.

All 2 comments

(base) marco@pc:~/detectron2$ python3 demo/demo.py --config-file

when you run python in the "detectron2" directory, it will use detectron2 that's in that directory, which is not compiled. It will not use the correct detectron2 that you installed to the system.

Ok thank you @ppwwyyxx !!!

Was this page helpful?
0 / 5 - 0 ratings