CenterNet2 icon indicating copy to clipboard operation
CenterNet2 copied to clipboard

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

Open xiyufeng2 opened this issue 3 years ago • 4 comments

When I run demo.py in Treminal, it's successful. But when running it in IDE(pycharm etc.), shows the error:ImportError: cannot import name '_C' from 'detectron2' (/home/ubuntu/CenterNet2/detectron2/init.py) 在终端运行成功,但在IDE运行失败(line11:from detectron2.data.detection_utils import read_image)

xiyufeng2 avatar Jun 29 '21 05:06 xiyufeng2

Hi, try to check the link below: https://github.com/facebookresearch/detectron2/issues/157

mohamed1986-collab avatar Jun 29 '21 07:06 mohamed1986-collab

I have seen that already,but not helpful.I have biult Detectron2 as instruction。

xiyufeng2 avatar Jun 29 '21 07:06 xiyufeng2

It's likely your terminal and IDE have different environments. Can you try to install a new conda environment and use the same one for both?

xingyizhou avatar Jun 29 '21 18:06 xingyizhou

Hi @xingyizhou ,

I was facing the same problem and got it to work following more or less the instructions in the previous issue.

Some details about how I did this:

My environment

name: wfsdet
channels:
  - conda-forge
  - defaults
dependencies:
  - python=3.7
  - cudatoolkit
  - pip
  - pip:
    - termcolor
    - cython
    - numpy
    - tqdm
    - matplotlib
    - termcolor
    - yacs
    - tabulate
    - cloudpickle
    - Pillow
    - imagesize
    - tensorboard
    - opencv-python
    - torch
    - torchvision
    - lvis
    - omegaconf>=2
    - iopath
    - git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI
    - git+https://github.com/facebookresearch/fvcore.git
  • Delete the old environment

This was deleted because when initially installed, along with Detectron2, the libgcc was not present. So, I had to clean it up.

conda remove --name wfsdet --all

  • Create and activate the environment
conda env create -f environment.yml
conda activate wfsdet
  • Update Conda and install libgcc
conda update -n base -c defaults conda
conda install -c conda-forge libgcc
  • Install Detectron2

python -m pip install 'git+https://github.com/facebookresearch/detectron2.git'

  • Test the environment
python -c "from detectron2 import _C"

It should output no error at all.

My setup:

  • GeForce RTX 2080i
  • Pop_OS (Ubuntu 18.04 based)
  • CUDA Version 10.2

wilderrodrigues avatar Jul 13 '21 17:07 wilderrodrigues