ModuleNotFoundError: No module named 'mmcv._ext'
mbspng opened this issue · 2 comments
This is now part of the setup script of a project of mine:
echo "Hacking MMDetection and MMDetection3D packages..."
# Why? Because docs (https://mmcv.readthedocs.io/en/latest/get_started/installation.html) say
#
# `pip install mmcv==2.2.0 -f https://download.openmmlab.com/mmcv/dist/cu121/torch2.4/index.html`
#
# (we used `uv add` of course) to match the other dependencies pinned in this repo.
#
# But then you end up with
#
# `AssertionError: MMCV==2.2.0 is used but incompatible. Please install mmcv>=2.0.0rc4, <2.2.0`.
#
# Right, makes sense, eh?!
#
# And when installing 2.1.0, you get
#
# `ModuleNotFoundError: No module named 'mmcv._ext'`.
#
# But when first installing 2.1.0, and then installing 2.2.0, and THEN hacking the `__init__.py` files, it works.
# So, here we are.
uv add mmcv==2.1.0 -f https://download.openmmlab.com/mmcv/dist/cu121/torch2.4/index.html
uv add mmcv==2.2.0 -f https://download.openmmlab.com/mmcv/dist/cu121/torch2.4/index.html
cp src/mmdet_init.py .venv/lib/python3.10/site-packages/mmdet/__init__.py
cp src/mmdet3d_init.py .venv/lib/python3.10/site-packages/mmdet3d/__init__.py
uv sync --all-extras
echo "Setup complete."
-> % cat src/mmdet3d_init.py
# Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import mmdet
import mmengine
from mmengine.utils import digit_version
from .version import __version__, version_info
mmcv_minimum_version = '2.0.0rc4'
mmcv_maximum_version = '2.2.0'
mmcv_version = digit_version(mmcv.__version__)
mmengine_minimum_version = '0.8.0'
mmengine_maximum_version = '1.0.0'
mmengine_version = digit_version(mmengine.__version__)
mmdet_minimum_version = '3.0.0rc5'
mmdet_maximum_version = '3.4.0'
mmdet_version = digit_version(mmdet.__version__)
# assert (mmcv_version >= digit_version(mmcv_minimum_version)
# and mmcv_version < digit_version(mmcv_maximum_version)), \
# f'MMCV=={mmcv.__version__} is used but incompatible. ' \
# f'Please install mmcv>={mmcv_minimum_version}, <{mmcv_maximum_version}.'
#
# assert (mmengine_version >= digit_version(mmengine_minimum_version)
# and mmengine_version < digit_version(mmengine_maximum_version)), \
# f'MMEngine=={mmengine.__version__} is used but incompatible. ' \
# f'Please install mmengine>={mmengine_minimum_version}, ' \
# f'<{mmengine_maximum_version}.'
#
# assert (mmdet_version >= digit_version(mmdet_minimum_version)
# and mmdet_version < digit_version(mmdet_maximum_version)), \
# f'MMDET=={mmdet.__version__} is used but incompatible. ' \
# f'Please install mmdet>={mmdet_minimum_version}, ' \
# f'<{mmdet_maximum_version}.'
__all__ = ['__version__', 'version_info', 'digit_version']
-> % cat src/mmdet_init.py
# Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import mmengine
from mmengine.utils import digit_version
from .version import __version__, version_info
mmcv_minimum_version = '2.0.0rc4'
mmcv_maximum_version = '2.2.0'
mmcv_version = digit_version(mmcv.__version__)
mmengine_minimum_version = '0.7.1'
mmengine_maximum_version = '1.0.0'
mmengine_version = digit_version(mmengine.__version__)
# assert (mmcv_version >= digit_version(mmcv_minimum_version)
# and mmcv_version < digit_version(mmcv_maximum_version)), \
# f'MMCV=={mmcv.__version__} is used but incompatible. ' \
# f'Please install mmcv>={mmcv_minimum_version}, <{mmcv_maximum_version}.'
#
# assert (mmengine_version >= digit_version(mmengine_minimum_version)
# and mmengine_version < digit_version(mmengine_maximum_version)), \
# f'MMEngine=={mmengine.__version__} is used but incompatible. ' \
# f'Please install mmengine>={mmengine_minimum_version}, ' \
# f'<{mmengine_maximum_version}.'
__all__ = ['__version__', 'version_info', 'digit_version']
├── mmdet v3.3.0 (extra: openmmlab)
├── mmdet3d v1.4.0 (extra: openmmlab)
├── torch v2.4.1 (extra: openmmlab)
├── torchaudio v2.4.1 (extra: openmmlab)
└── torchvision v0.19.1 (extra: openmmlab)
python 3.10.13
I think that speaks for itself.
Same issue here , tried to install directly mmcv 2.2.0 , fails building the wheel, 2.0.4, says that it couldt find mmcv , im so confused because the google colab book is quite outdated at this point and for some is the only way to compile faster
I managed to resolve the mmcv._ext
issue when running the test installation script: python demo/image_demo.py demo/demo.jpg rtmdet_tiny_8xb32-300e_coco.py --weights rtmdet_tiny_8xb32-300e_coco_20220902_112414-78e30dcc.pth --device cpu
!
I have an M3 Pro and a Python 3.11 miniconda installation. I created a virtual environment with python -m venv venv
. Then, I installed the following packages:
pip install torch==2.1.2
pip install torchvision==0.16.2
pip install numpy==1.26.4
pip install openmim
mim install mmengine
mim install "mmcv==2.1.0"
mim install mmdet
I found it's important to use mim
and not pip
when installing the openmmlab packages.