open-mmlab / mmdetection

OpenMMLab Detection Toolbox and Benchmark
https://mmdetection.readthedocs.io
Apache License 2.0
29.45k stars 9.43k forks source link

ModuleNotFoundError: No module named 'mmcv._ext' #3271

Closed ahchang2 closed 4 years ago

ahchang2 commented 4 years ago

Someone has already post this issue earlier, and I just wanna say I got the same issue. I'm using mmedetection on colab. I installed the program as usual, but when I tried to import inference_detector from mmdet.apis, I got the error as described in the title which I've never met before. I thought it may because some updates on your side were on progress, but I wasn't sure. Any suggestion? Thank you.

francescotaioli commented 2 years ago

Install from the sources worked for me, follow below steps.

* $git clone https://github.com/open-mmlab/mmcv.git

* $cd mmcv

* $MMCV_WITH_OPS=1 python3 -m pip install -e . # package mmcv-full will be installed after this step

This fix also for me. I would add that I installed this specific version of pytorch

fingertap commented 2 years ago

The key is to add MMCV_WITH_OPS=1, so that you are installing mmcv-full, rather than mmcv, which has no support for GPUs.

wulala-max commented 2 years ago

AssertionError: active_rotated_filter_forward miss in module _ext

Traceback (most recent call last): File "tools/train.py", line 9, in from mmdet.apis import (get_root_logger, init_dist, set_random_seed, File "/home/vipuser/Desktop/mmdetection/mmdet/apis/init.py", line 2, in from .inference import (async_inference_detector, inference_detector, File "/home/vipuser/Desktop/mmdetection/mmdet/apis/inference.py", line 7, in from mmcv.ops import RoIPool File "/home/vipuser/miniconda3/envs/open-mmlab/lib/python3.7/site-packages/mmcv/ops/init.py", line 2, in from .active_rotated_filter import active_rotated_filter File "/home/vipuser/miniconda3/envs/open-mmlab/lib/python3.7/site-packages/mmcv/ops/active_rotated_filter.py", line 10, in ['active_rotated_filter_forward', 'active_rotated_filter_backward']) File "/home/vipuser/miniconda3/envs/open-mmlab/lib/python3.7/site-packages/mmcv/utils/ext_loader.py", line 15, in load_ext assert hasattr(ext, fun), f'{fun} miss in module {name}' AssertionError: active_rotated_filter_forward miss in module _ext

GeneralJing commented 2 years ago

2022-05-10:09:11:58,root ERROR [utils.py:43] active_rotated_filter_forward miss in module _ext Traceback (most recent call last): File "/home/data/projects/work/MMDeploy/mmdeploy/utils/utils.py", line 38, in target_wrapper result = target(*args, *kwargs) File "/home//data/projects/work/MMDeploy/mmdeploy/apis/pytorch2onnx.py", line 102, in torch2onnx task_processor = build_task_processor(model_cfg, deploy_cfg, device) File "/home/data/projects/work/MMDeploy/mmdeploy/apis/utils.py", line 21, in build_task_processor import_codebase(codebase_type) File "/home/data/projects/work/MMDeploy/mmdeploy/codebase/init.py", line 30, in import_codebase importlib.import_module(f'mmdeploy.codebase.{lib}') File "/opt/conda/lib/python3.8/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1014, in _gcd_import File "", line 991, in _find_and_load File "", line 975, in _find_and_load_unlocked File "", line 671, in _load_unlocked File "", line 843, in exec_module File "", line 219, in _call_with_frames_removed File "/home//data/projects/work/MMDeploy/mmdeploy/codebase/mmdet3d/init.py", line 2, in from .deploy import MMDetection3d, VoxelDetection File "/home/data/projects/work/MMDeploy/mmdeploy/codebase/mmdet3d/deploy/init.py", line 3, in from .voxel_detection import VoxelDetection File "/home/data/projects/work/MMDeploy/mmdeploy/codebase/mmdet3d/deploy/voxel_detection.py", line 9, in from mmdet3d.core.bbox import get_box_type File "/home//data/projects/work/mmdetection3d/mmdet3d/core/init.py", line 2, in from .anchor import # noqa: F401, F403 File "/home/data/projects/work/mmdetection3d/mmdet3d/core/anchor/init.py", line 2, in from mmdet.core.anchor import build_prior_generator File "/home/data/projects/work/mmdetection/mmdet/core/init.py", line 3, in from .bbox import * # noqa: F401, F403 File "/home/data/projects/work/mmdetection/mmdet/core/bbox/init.py", line 8, in from .samplers import (BaseSampler, CombinedSampler, File "/home/data/projects/work/mmdetection/mmdet/core/bbox/samplers/init.py", line 12, in from .score_hlr_sampler import ScoreHLRSampler File "/home/data/projects/work/mmdetection/mmdet/core/bbox/samplers/score_hlr_sampler.py", line 3, in from mmcv.ops import nms_match File "/opt/conda/lib/python3.8/site-packages/mmcv/ops/init.py", line 2, in from .active_rotated_filter import active_rotated_filter File "/opt/conda/lib/python3.8/site-packages/mmcv/ops/active_rotated_filter.py", line 8, in ext_module = ext_loader.load_ext( File "/opt/conda/lib/python3.8/site-packages/mmcv/utils/ext_loader.py", line 15, in load_ext assert hasattr(ext, fun), f'{fun} miss in module {name}' AssertionError: active_rotated_filter_forward miss in module _ext 2022-05-10 09:11:59,143 - mmdeploy - ERROR - torch2onnx failed.

timtheuz commented 2 years ago

For people still struggling with this error: ModuleNotFoundError: No module named 'mmcv._ext'

  1. It's important that pytorch - cuda - mmcv are compatible
  2. Therefore first you should check your cuda version nvidia-smi
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 450.102.04   Driver Version: 450.102.04   CUDA Version: 11.0     |
|-------------------------------+----------------------+----------------------+

For example mine is 11.0

  1. Then download correct pytorch:
pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html

This is Pytorch 1.8.0 with cuda 11.1.

  1. Install correct mmcv as they mention in their README
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.8.0/index.html

/cu111/torch1.8.0/ see how cuda and torch versions are matching

  1. It should work 😃
Python 3.7.5 (default, Feb 23 2021, 13:22:40) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from mmcv.ops import get_compiling_cuda_version, get_compiler_version
>>> print(get_compiling_cuda_version())
11.1
>>> print(get_compiler_version())
GCC 7.3
>>> 

PS Here's our project where we used mmdet

Adding to your reply: Compatibility between pytorch - mmcv - cuda for devices without a specific GPU (only CPU) also means to use the CPU-only option during installation. Installation steps varied during my project walkthrough, e.g. for mmcv installation I used

conda install pytorch torchvision cpuonly -c pytorch

instead of

conda install pytorch torchvision -c pytorch

Source

whybeyoung commented 2 years ago

Curious About that no one have a correct answer.

Please use: pip uninstall mmcv-full pip install mmcv-full --no-binary :all: my version is 1.6.1

Akshaypatil15 commented 2 years ago

Curious About that no one have a correct answer.

Please use: pip uninstall mmcv-full pip install mmcv-full --no-binary :all: my version is 1.6.1

Work perfectly for CPU inference.

116022017144 commented 1 year ago

I also meet the problem." AssertionError: MMCV==1.7.0 is used but incompatible. Please install mmcv>=1.3.2, <=1.4.0."

DNQuAng10 commented 1 year ago

Same error "ModuleNotFoundError: No module named 'mmcv._ext'". I fixed it by:

ShaihW commented 1 year ago

I see this issue still happening I found that instead of install and then uninstall and install again, it is better to find the version that fits your machine. for example my machine uses cuda10.2 torch 1.10.0, so I found the adequate .whl here: https://download.openmmlab.com/mmcv/dist/cu102/torch1.10.0/index.html

hello-world-zsp commented 1 year ago

https://mmcv.readthedocs.io/en/latest/get_started/installation.html#install-mmcv-full Install following the official doc and find the correct version works for me. image

ShaihW commented 1 year ago

https://mmcv.readthedocs.io/en/latest/get_started/installation.html#install-mmcv-full Install following the official doc and find the correct version works for me. image

afaik this is not valid in case we want mmdetection v3.0.0rc it requires mmcv v2.0.0rc

Amr-Mustafa commented 1 year ago

https://mmcv.readthedocs.io/en/latest/get_started/installation.html#install-mmcv-full Install following the official doc and find the correct version works for me. image

This works for me as well!

pietermarsman commented 1 year ago

I got this error with mmcv==2.0.0. From the v2 release this is equivalent to installing the mmcv-full package (see the release notes). So the suggestions from above are outdated.

I solved it by installing mmcv from source using

pip install --no-binary mmcv --pep517 mmcv==2.0.0
mohdsaqibxa commented 1 year ago

https://mmcv.readthedocs.io/en/latest/get_started/installation.html#install-mmcv-full Install following the official doc and find the correct version works for me. image

What version of mmsegmentation you installed with it?

lobanov-m commented 1 year ago

I solved this issue with

pip install mmcv-full==1.6.2 --no-cache

Looks like pip for some reason cached bad version of mmcv-full and it blocked right installation from remote.

nicolefinnie commented 1 year ago

no-binary

This should be marked as the right answer, so it tries to install from the source. It finally solved this issue for me.

IanLynnEE commented 1 year ago

I was facing the same issue at v3.2.0 with mmcv v2.0.1 installed by mim. Managed to solve it by downgrading PyTorch to 1.13.1+cu117 and reinstalling mmcv.

mmcv is only compiled on PyTorch 1.x.0 because the compatibility usually holds between 1.x.0 and 1.x.1.

pyenv virtualenv 3.8.6 openmmlab
pyenv activate openmmlab
pip install torch==1.13.1+cu117 torchvision==0.14.1+cu117 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu117
carlosgomez1987 commented 1 year ago

Curious About that no one have a correct answer.

Please use: pip uninstall mmcv-full pip install mmcv-full --no-binary :all: my version is 1.6.1

imagen

carlosgomez1987 commented 1 year ago

Install from the sources worked for me, follow below steps.

* $git clone https://github.com/open-mmlab/mmcv.git

* $cd mmcv

* $MMCV_WITH_OPS=1 python3 -m pip install -e . # package mmcv-full will be installed after this step

Was taken so much time. I'm using colab

1

2

nouranali commented 12 months ago

Install from the sources worked for me, follow below steps.

* $git clone https://github.com/open-mmlab/mmcv.git

* $cd mmcv

* $MMCV_WITH_OPS=1 python3 -m pip install -e . # package mmcv-full will be installed after this step

Was taken so much time. I'm using colab

1

2

Yes I still have the same issue

Ishu-Kalra commented 11 months ago

Well, I am on macbook pro M2 chip and none of these solutions worked for me :(

satani99 commented 10 months ago

@Ishu-Kalra hey have you found any solution to this error?

bs7280 commented 10 months ago

@Ishu-Kalra and others who are trying to run this on an M1 / M2 / M3

Make sure you use this link to download the package specific for your system shared by @ mohdsaqibxa

carlosgomez1987 commented 10 months ago

Install from the sources worked for me, follow below steps.

* $git clone https://github.com/open-mmlab/mmcv.git

* $cd mmcv

* $MMCV_WITH_OPS=1 python3 -m pip install -e . # package mmcv-full will be installed after this step

Was taken so much time. I'm using colab 1 2

Yes I still have the same issue

I resolve this issue by following this command on Google Colab !pip install openmim mmengine !mim install mmcv

!rm -rf mmdetection !git clone https://github.com/open-mmlab/mmdetection.git %cd mmdetection !pip install -e .

seginusmowlavi commented 9 months ago

@Ishu-Kalra I encountered the issue and found a solution, on a M2 chip.

The issue: when running the verification steps for mmocr (which requires mmcv<2.2.0,>=2.0.0rc4), I got

ModuleNotFoundError: No module named 'mmcv._ext'

The solution: forcing mmcv to be installed with setup.py, by using pip<23.1 and --no-cache-dir. The following worked:

pip install pip==23.0.1
pip install --no-cache-dir mmcv==2.0.1

Notes: worked on Python 3.10.13|3.11.7 (<3.12 needed for pip 23.0.1) and torch 2.0.1 (chosen because torch 1.13.x has a bug related to MPS).

rkj12345 commented 9 months ago

I tried my method and it solved the problem, you can try it.

  1. Remove the mmcv and mmcv-full packages from your conda environment.
  2. Then run the following command to install the mmcv package

pip install -U openmim mim install mmcv-full==1.7.0

vetsasai commented 8 months ago

I have face same issue with mmcv-full [v1.6.0], mmdet [2.24.0], torch [1.9.0] + CUDA [11.1] and i cant use another version of mmcv-full due to certain dependancies.

However, it is found that the missing module mmcv._ext is a installation generated file '/lib/python3.8/site-packages/mmcv/_ext.cpython-38-x86_64-linux-gnu.so'. Somehow, mmcv-full[1.6.0] pip/mim installation didnt generate me this file. So I had to install mmcv-full[1.7.2] which generated this specific _ext.cpythonblablablah file and I copied it to mmcv-full[1.6.0] folder and using it just fine.

Will have to see how far it holds my cause!

Update 1: when I install mmcv 1.6.0 from source with MMCV_WITH_OPS=1 & FORCE_CUDA=1, everything works good.

alon1samuel commented 6 months ago

Still installing mmcv was a problem for me I'm on a linux machine and what helped me was downgrade torch==2.2.2 to torch==2.1.0 after seeing in here

image

that there was no installation for torch==2.2.x but only for torch==2.1.x

Then I've installed as they said:

pip install mmcv==2.1.0 -f https://download.openmmlab.com/mmcv/dist/cu121/torch2.1/index.html

Previous help above didn't help for me (mmcv-full or mim install mmcv, ...)

Hope it helps!

dierfeichai2 commented 6 months ago

Curious About that no one have a correct answer.

Please use: pip uninstall mmcv-full pip install mmcv-full --no-binary :all: my version is 1.6.1

Have been struggling in this problem for quite a long time, this ACTUALLY solves my problem! Many thanks!

maximefuchs commented 6 months ago

I've been trying to fix this bug while using mmdeploy. mmdeploy requires mmcv>=2.0.0rc2 and <2.1.0 and I keep getting the no module mmcv._ext error with the allowed versions. Any updates on this issue?

seginusmowlavi commented 6 months ago

@maximefuchs What's your version of pip? Have you tried the following?

pip install pip==23.0.1
pip install --no-cache-dir mmcv==2.0.1
maximefuchs commented 6 months ago

My version of pip is 24.0 By doing what you suggested, I can't manage to install mmcv. It returns an error during the installation and fails to build the wheel:

error: command '/usr/bin/nvcc' failed with exit code 1

With pip 24.0, the installation is succesful but running the following deploy command (comes from the installation guide) gives No module named 'mmcv._ext':

# run the command to start model conversion
python mmdeploy/tools/deploy.py \
    mmdeploy/configs/mmdet/detection/detection_tensorrt_dynamic-320x320-1344x1344.py \
    mmdetection/configs/faster_rcnn/faster-rcnn_r50_fpn_1x_coco.py \
    checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth \
    mmdetection/demo/demo.jpg \
    --work-dir mmdeploy_model/faster-rcnn \
    --device cuda \
    --dump-info
yokosyun commented 5 months ago

install mmcv with newer version

mim install mmcv=='2.2.0' # just install newer version

version requirement

  File "xxxxxxxx/mmdetection3d/mmdet3d/__init__.py", line 21, in <module>
    assert (mmcv_version >= digit_version(mmcv_minimum_version)
AssertionError: MMCV==2.2.0 is used but incompatible. Please install mmcv>=2.0.0rc4, <2.2.0.

not recommended solution

mmdetection3d/mmdet3d/init.py

- mmcv_maximum_version = "2.2.0"
+ mmcv_maximum_version = "2.3.0" # just set any version higher than your mmcv
maximefuchs commented 5 months ago

Hi ! Yes, I changed the minimum required version in the code and it correctly installed the library. The export is working as well. Thanks !

Le mar. 21 mai 2024 à 20:00, Allwyn Joseph @.***> a écrit :

My version of pip is 24.0 By doing what you suggested, I can't manage to install mmcv. It returns an error during the installation and fails to build the wheel:

error: command '/usr/bin/nvcc' failed with exit code 1

With pip 24.0, the installation is succesful but running the following deploy command (comes from the installation guide) gives No module named 'mmcv._ext':

run the command to start model conversion

python mmdeploy/tools/deploy.py \ mmdeploy/configs/mmdet/detection/detection_tensorrt_dynamic-320x320-1344x1344.py \ mmdetection/configs/faster_rcnn/faster-rcnn_r50_fpn_1x_coco.py \ checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth \ mmdetection/demo/demo.jpg \ --work-dir mmdeploy_model/faster-rcnn \ --device cuda \ --dump-info

Hey maxime, Were you able to fix the issue of No module named 'mmcv._ext' ?

— Reply to this email directly, view it on GitHub https://github.com/open-mmlab/mmdetection/issues/3271#issuecomment-2123155498, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALH6AI2HN2LTXVVAWZUFQC3ZDODSVAVCNFSM4OWHCNKKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMJSGMYTKNJUHE4A . You are receiving this because you were mentioned.Message ID: @.***>

agirishkumar commented 3 months ago

I still have the problem, i needed multiple mm*libs mmcv, mmdetection, mmclassification, mmtracking. trying to let all these work together i kept on downgrading, though everything got installed, i am still getting the same error ModuleNotFoundError: No module named 'mmcv._ext'

following are the versions i am using: mmcv v1.3.17 mmdetection v2.14.0 mmclassification v0.19.0 mmtracking v0.8.0

cudatoolkit 11.1 cudnn 8 torch 1.8.0

i tried installing these through openmim, pip, finally had better success installing from source

christinab12 commented 3 months ago

install mmcv with newer version

mim install mmcv=='2.2.0' # just install newer version

version requirement

  File "xxxxxxxx/mmdetection3d/mmdet3d/__init__.py", line 21, in <module>
    assert (mmcv_version >= digit_version(mmcv_minimum_version)
AssertionError: MMCV==2.2.0 is used but incompatible. Please install mmcv>=2.0.0rc4, <2.2.0.

not recommended solution

mmdetection3d/mmdet3d/init.py

- mmcv_maximum_version = "2.2.0"
+ mmcv_maximum_version = "2.3.0" # just set any version higher than your mmcv

This solution is working for me on MacOS, but strangely not on Windows or Linux systems. Current Environment:

Python==3.10
Torch==2.3.1
mmdet==3.3.0
mmcv==2.2.0

These are depecndencies from the package I am building so I need to install with pip and be compatible accross different OS.. Any ideas?