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.

ahchang2 commented 4 years ago

And also, I received the link to the page of installing mmdet on colab from one of you earlier in another issue I posted. This is the address as I opened the page on colab (https://github.com/openmmlab/mmdetection/blob/master/demo/mmdet_inference_colab.ipynb) However, when I rechecked the page after the error occurred, it was gone.

qianwangn commented 4 years ago

same problem.

xvjiarui commented 4 years ago

Hi @ahchang2 You may try to install mmcv==0.6.2.

ShidiDaisy commented 4 years ago

Hi @ahchang2 You may try to install mmcv==0.6.2.

But I received another error after install mmcv==0.6.2

Traceback (most recent call last): File "tools/train.py", line 13, in from mmdet.apis import set_random_seed, train_detector File "/home/ubuntu/mmdetection/mmdet/apis/init.py", line 1, in from .inference import (async_inference_detector, inference_detector, File "/home/ubuntu/mmdetection/mmdet/apis/inference.py", line 6, in from mmcv.ops import RoIAlign, RoIPool ModuleNotFoundError: No module named 'mmcv.ops'

xvjiarui commented 4 years ago

@ShidiDaisy There basically are two workarounds.

  1. Install latest mmdet and pip install mmcv-full or install pre-build ones from here.
  2. Install mmcv==0.6.2 and mmdet==2.2.1
ShidiDaisy commented 4 years ago

@ShidiDaisy There basically are two workarounds.

  1. Install latest mmdet and pip install mmcv-full or install pre-build ones from here.
  2. Install mmcv==0.6.2 and mmdet==2.2.1

But I still hit this error after I pip install mmcv-full.

Traceback (most recent call last): File "tools/train.py", line 153, in main() File "tools/train.py", line 126, in main cfg.model, train_cfg=cfg.train_cfg, test_cfg=cfg.test_cfg) File "/home/ubuntu/mmdetection/mmdet/models/builder.py", line 65, in build_detector return build(cfg, DETECTORS, dict(train_cfg=train_cfg, test_cfg=test_cfg)) File "/home/ubuntu/mmdetection/mmdet/models/builder.py", line 30, in build return build_from_cfg(cfg, registry, default_args) File "/home/ubuntu/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/mmcv/utils/registry.py", line 167, in build_from_cfg return obj_cls(**args) TypeError: init() got an unexpected keyword argument 'bbox_roi_extractor'

I also tried 'python setup.py develop',but still can't get rid of the error.

VANRao-Stack commented 4 years ago

@ShidiDaisy There basically are two workarounds.

  1. Install latest mmdet and pip install mmcv-full or install pre-build ones from here.
  2. Install mmcv==0.6.2 and mmdet==2.2.1

I was getting ModuleNotFoundError: No module named 'mmcv.ops', so I tried installing mmcv==0.6.2 and mmdet==2.2.1, but then I got the error, ERROR: No matching distribution found for mmdet==2.2.1. The training was working when I installed mmcv-full however I was having the same issue as #3259, so I'm currently following the Author of the issue #3259, solution. Any help would be appreciated.

Vankeee commented 4 years ago

Same error. Oh my god.

ghost commented 4 years ago

This works 100%.

export TORCH_CUDA_ARCH_LIST="6.0 6.1 7.0+PTX"
export  TORCH_NVCC_FLAGS="-Xfatbin -compress-all"
export  CMAKE_PREFIX_PATH="$(dirname $(which conda))/../"

pip uninstall -y mmdet mmcv
conda install -y cython==0.28.5
#pip install mmcv==0.2.15
pip install mmcv==0.6.2 terminaltables Pillow==6.2.2

export FORCE_CUDA="1"

pip install "git+https://github.com/open-mmlab/cocoapi.git#subdirectory=pycocotools"
pip install "git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI"
#git clone https://github.com/open-mmlab/mmdetection.git mmdetection
#cd mmdetection
rm -rf build
pip install -r requirements/build.txt
python setup.py develop
pip install --no-cache-dir -e .
pip install mmcv==0.6.2 mmcv-full
ShidiDaisy commented 4 years ago

This works 100%.

export TORCH_CUDA_ARCH_LIST="6.0 6.1 7.0+PTX"
export  TORCH_NVCC_FLAGS="-Xfatbin -compress-all"
export  CMAKE_PREFIX_PATH="$(dirname $(which conda))/../"

pip uninstall -y mmdet mmcv
conda install -y cython==0.28.5
#pip install mmcv==0.2.15
pip install mmcv==0.6.2 terminaltables Pillow==6.2.2

export FORCE_CUDA="1"

pip install "git+https://github.com/open-mmlab/cocoapi.git#subdirectory=pycocotools"
pip install "git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI"
#git clone https://github.com/open-mmlab/mmdetection.git mmdetection
#cd mmdetection
rm -rf build
pip install -r requirements/build.txt
python setup.py develop
pip install --no-cache-dir -e .
pip install mmcv==0.6.2 mmcv-full

But I still got this issue after following your solution. Have you seen this issue?

Traceback (most recent call last): File "demo/image_demo.py", line 3, in from mmdet.apis import inference_detector, init_detector, show_result_pyplot File "/home/ubuntu/mmdetection/mmdet/apis/init.py", line 1, in from .inference import (async_inference_detector, inference_detector, File "/home/ubuntu/mmdetection/mmdet/apis/inference.py", line 6, in from mmcv.ops import RoIAlign, RoIPool File "/home/ubuntu/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/mmcv/ops/init.py", line 1, in from .bbox import bbox_overlaps File "/home/ubuntu/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/mmcv/ops/bbox.py", line 3, in ext_module = ext_loader.load_ext('_ext', ['bbox_overlaps']) File "/home/ubuntu/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/mmcv/utils/ext_loader.py", line 12, in load_ext assert hasattr(ext, fun), f'{fun} miss in module {name}' AssertionError: bbox_overlaps miss in module _ext

xvjiarui commented 4 years ago

Hi @ShidiDaisy Please first uninstall any previous version of mmcv. And run pip install mmcv-full. Please refer to install guide for details.

peeyushpashine commented 4 years ago

@xvjiarui Following latest install guide and cloned lastest master branch code. I receive the error: ModuleNotFoundError: No module named 'mmcv._ext'

xvjiarui commented 4 years ago

Hi @peeyushpashine You need to install mmcv-full. You may run pip install mmcv-full.

peeyushpashine commented 4 years ago

@xvjiarui Yes, still the same issue.

ShidiDaisy commented 4 years ago

Hi @ShidiDaisy Please first uninstall any previous version of mmcv. And run pip install mmcv-full. Please refer to install guide for details.

But I got this issue:

import mmcv ModuleNotFoundError: No module named 'mmcv'

after I pip uninstall mmcv, pip install mmcv-full

ZwwWayne commented 4 years ago

Hi @peeyushpashine , @ShidiDaisy , You may need to use pip uninstall mmcv multiple times to ensure that there is no old mmcv in the python site-packages first. Some times the mmcv might not be totally wiped out for some reasons. Then you can install mmcv-full using pip install mmcv-full. Please ensure that this time mmcv is successfully compiled and installed.

deepaksinghcv commented 4 years ago

I did a fresh build with a new environment, and everything works as expected.

helloMickey commented 4 years ago

Hi @peeyushpashine You need to install mmcv-full. You may run pip install mmcv-full.

useless

david-littlefield commented 4 years ago

Perhaps it's a path related issue? The following command worked:

python -m pip install mmcv==0.6.2
peeyushpashine commented 4 years ago

Somehow in the latest master code i do not see issue anymore.

vadimtimakin commented 4 years ago

Here is the complete solution by setting all requirements:

from IPython.display import clear_output

os.environ['PYTHONPATH'] = "/usr/bin/python3" !wget https://repo.continuum.io/miniconda/Miniconda3-4.5.4-Linux-x86_64.sh && bash Miniconda3-4.5.4-Linux-x86_64.sh -bfp /usr/local

!conda create -n open-mmlab python=3.7 -y !conda activate open-mmlab !conda install --yes pytorch torchvision -c pytorch !conda install --yes pytorch cudatoolkit=10.1 torchvision -c pytorch

!pip install mmcv-full !git clone <YOUR GIT REPO> !pip install mmcv

!pip install -r /content/mmdetection/requirements/build.txt !pip install -v -e . # or "python setup.py develop" !pip install -r /content/mmdetection/requirements/optional.txt

%cd mmdetection !python setup.py develop !conda install --yes ipykernel

clear_output(wait=True) print('Done!')

ZwwWayne commented 4 years ago

Here is the complete solution by setting all requirements:

from IPython.display import clear_output

os.environ['PYTHONPATH'] = "/usr/bin/python3" !wget https://repo.continuum.io/miniconda/Miniconda3-4.5.4-Linux-x86_64.sh && bash Miniconda3-4.5.4-Linux-x86_64.sh -bfp /usr/local

!conda create -n open-mmlab python=3.7 -y !conda activate open-mmlab !conda install --yes pytorch torchvision -c pytorch !conda install --yes pytorch cudatoolkit=10.1 torchvision -c pytorch

!pip install mmcv-full !git clone <YOUR GIT REPO> !pip install mmcv

!pip install -r /content/mmdetection/requirements/build.txt !pip install -v -e . # or "python setup.py develop" !pip install -r /content/mmdetection/requirements/optional.txt

%cd mmdetection !python setup.py develop !conda install --yes ipykernel

clear_output(wait=True) print('Done!')

If you installed mmcv-full, you should not install mmcv. You can try to not install mmcv and see if it works.

liuligang123 commented 4 years ago

I run the MMCV_WITH_OPS=1 pip install -e . and then solve the problem just wait when running setup.py develop for mmcv-full

sisse008 commented 4 years ago

pip uninstall mmcv pip install mmcv-full

curehabit commented 4 years ago

I fixed by pip install mmcv-full==1.0.5 It may depend on version?

cll011 commented 4 years ago

first: pip uninstall mmcv then: pip install mmcv-full==latest+torch1.5.0+cu101 -f https://download.openmmlab.com/mmcv/dist/index.html my mmdet version is 2.4.0, mmcv>=1.1.0

chengzi999 commented 4 years ago

If you have installed the correct version of cfg,remember use 'conda active mmdet'. It works

dreamflasher commented 3 years ago

Can you please add mmcv-full as a dependency here in mmdet? Also just ran into this error. Also why does this need 10 minutes to install? Oo

surendrallam commented 3 years ago

First uninstall MMCV and MMCV-Full pip uninstall mmcv mmcv-full

Install MMCV from source. git clone https://github.com/open-mmlab/mmcv.git cd mmcv MMCV_WITH_OPS=1 python3 -m pip install -e . Note: Make sure that you are installing in respected Python and pip.

dtlam26 commented 3 years ago

Install your mmcv-full correctly by pip install the according wheel version with your configuration in here. Scroll down for latest update

surendrallam commented 3 years ago

Thanks for the reply, resolved the issue installing it from sources.

Thanks and Regards, Surendra Allam.

Sent from my iPhone

On 26-Jan-2021, at 8:21 AM, Duong Tung Lam notifications@github.com wrote:



Install your mmcv-full correctly by pip install the according wheel version with your configuration in [here]. Scroll down for latest update (https://download.openmmlab.com/mmcv/dist/index.html)

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/open-mmlab/mmdetection/issues/3271#issuecomment-767253173, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AK63YVL5M332G3BVAN5QGF3S3YU2JANCNFSM4OWHCNKA.

rh-ia commented 3 years ago

Using google colab (march 2021) succesfully installed using:

%%bash
pip install torch==1.7.0
pip install mmdet==2.4.0
pip uninstall mmcv
pip install mmcv-full==latest+torch1.7.0+cu110 -f https://download.openmmlab.com/mmcv/dist/index.html
luooofan commented 3 years ago

First uninstall MMCV and MMCV-Full pip uninstall mmcv mmcv-full

Install MMCV from source. git clone https://github.com/open-mmlab/mmcv.git cd mmcv MMCV_WITH_OPS=1 python3 -m pip install -e . Note: Make sure that you are installing in respected Python and pip.

It works well for me. Thanks!

Environment:

TheFebrin commented 3 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.

  2. 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

  3. 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

kapil-varshney commented 3 years ago

I am facing the same issue.

Python 3.7.10 (default, Feb 26 2021, 13:06:18) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from mmcv.ops import get_compiling_cuda_version, get_compiler_version
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\kap10429\tasks\32_mmdetection\mmcv\mmcv\ops\__init__.py", line 1, in <module>
    from .bbox import bbox_overlaps
  File "C:\Users\kap10429\tasks\32_mmdetection\mmcv\mmcv\ops\bbox.py", line 3, in <module>
    ext_module = ext_loader.load_ext('_ext', ['bbox_overlaps'])
  File "C:\Users\kap10429\tasks\32_mmdetection\mmcv\mmcv\utils\ext_loader.py", line 11, in load_ext
    ext = importlib.import_module('mmcv.' + name)
  File "C:\Users\kap10429\Anaconda3\envs\open-mmlab\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'mmcv._ext'

OS: Windows 10

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 461.09       Driver Version: 461.09       CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+

Steps to setup:

conda install pytorch==1.7.0 torchvision==0.8.0 cudatoolkit=11.0 -c pytorch
git clone https://github.com/open-mmlab/mmcv.git
cd mmcv
python -m pip install -e .

Please let me know if anyone has had success with Windows in regards to this issue.

KKhushhalR2405 commented 3 years ago

I am facing the same issue.

Python 3.7.10 (default, Feb 26 2021, 13:06:18) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from mmcv.ops import get_compiling_cuda_version, get_compiler_version
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\kap10429\tasks\32_mmdetection\mmcv\mmcv\ops\__init__.py", line 1, in <module>
    from .bbox import bbox_overlaps
  File "C:\Users\kap10429\tasks\32_mmdetection\mmcv\mmcv\ops\bbox.py", line 3, in <module>
    ext_module = ext_loader.load_ext('_ext', ['bbox_overlaps'])
  File "C:\Users\kap10429\tasks\32_mmdetection\mmcv\mmcv\utils\ext_loader.py", line 11, in load_ext
    ext = importlib.import_module('mmcv.' + name)
  File "C:\Users\kap10429\Anaconda3\envs\open-mmlab\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'mmcv._ext'

OS: Windows 10

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 461.09       Driver Version: 461.09       CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+

Steps to setup:

conda install pytorch==1.7.0 torchvision==0.8.0 cudatoolkit=11.0 -c pytorch
git clone https://github.com/open-mmlab/mmcv.git
cd mmcv
python -m pip install -e .

Please let me know if anyone has had success with Windows in regards to this issue.

Which version of mmcv-full are you using??

kapil-varshney commented 3 years ago

I am facing the same issue.

Python 3.7.10 (default, Feb 26 2021, 13:06:18) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from mmcv.ops import get_compiling_cuda_version, get_compiler_version
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\kap10429\tasks\32_mmdetection\mmcv\mmcv\ops\__init__.py", line 1, in <module>
    from .bbox import bbox_overlaps
  File "C:\Users\kap10429\tasks\32_mmdetection\mmcv\mmcv\ops\bbox.py", line 3, in <module>
    ext_module = ext_loader.load_ext('_ext', ['bbox_overlaps'])
  File "C:\Users\kap10429\tasks\32_mmdetection\mmcv\mmcv\utils\ext_loader.py", line 11, in load_ext
    ext = importlib.import_module('mmcv.' + name)
  File "C:\Users\kap10429\Anaconda3\envs\open-mmlab\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'mmcv._ext'

OS: Windows 10

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 461.09       Driver Version: 461.09       CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+

Steps to setup:

conda install pytorch==1.7.0 torchvision==0.8.0 cudatoolkit=11.0 -c pytorch
git clone https://github.com/open-mmlab/mmcv.git
cd mmcv
python -m pip install -e .

Please let me know if anyone has had success with Windows in regards to this issue.

Which version of mmcv-full are you using??

I am using the latest clone. It is v1.3.0

KKhushhalR2405 commented 3 years ago

I am facing the same issue.

Python 3.7.10 (default, Feb 26 2021, 13:06:18) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from mmcv.ops import get_compiling_cuda_version, get_compiler_version
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\kap10429\tasks\32_mmdetection\mmcv\mmcv\ops\__init__.py", line 1, in <module>
    from .bbox import bbox_overlaps
  File "C:\Users\kap10429\tasks\32_mmdetection\mmcv\mmcv\ops\bbox.py", line 3, in <module>
    ext_module = ext_loader.load_ext('_ext', ['bbox_overlaps'])
  File "C:\Users\kap10429\tasks\32_mmdetection\mmcv\mmcv\utils\ext_loader.py", line 11, in load_ext
    ext = importlib.import_module('mmcv.' + name)
  File "C:\Users\kap10429\Anaconda3\envs\open-mmlab\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'mmcv._ext'

OS: Windows 10

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 461.09       Driver Version: 461.09       CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+

Steps to setup:

conda install pytorch==1.7.0 torchvision==0.8.0 cudatoolkit=11.0 -c pytorch
git clone https://github.com/open-mmlab/mmcv.git
cd mmcv
python -m pip install -e .

Please let me know if anyone has had success with Windows in regards to this issue.

Which version of mmcv-full are you using??

I am using the latest clone. It is v1.3.0

Switch to version 1.2.4. It worked for me

kapil-varshney commented 3 years ago

I am facing the same issue.

Python 3.7.10 (default, Feb 26 2021, 13:06:18) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from mmcv.ops import get_compiling_cuda_version, get_compiler_version
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\kap10429\tasks\32_mmdetection\mmcv\mmcv\ops\__init__.py", line 1, in <module>
    from .bbox import bbox_overlaps
  File "C:\Users\kap10429\tasks\32_mmdetection\mmcv\mmcv\ops\bbox.py", line 3, in <module>
    ext_module = ext_loader.load_ext('_ext', ['bbox_overlaps'])
  File "C:\Users\kap10429\tasks\32_mmdetection\mmcv\mmcv\utils\ext_loader.py", line 11, in load_ext
    ext = importlib.import_module('mmcv.' + name)
  File "C:\Users\kap10429\Anaconda3\envs\open-mmlab\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'mmcv._ext'

OS: Windows 10

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 461.09       Driver Version: 461.09       CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+

Steps to setup:

conda install pytorch==1.7.0 torchvision==0.8.0 cudatoolkit=11.0 -c pytorch
git clone https://github.com/open-mmlab/mmcv.git
cd mmcv
python -m pip install -e .

Please let me know if anyone has had success with Windows in regards to this issue.

Which version of mmcv-full are you using??

I am using the latest clone. It is v1.3.0

Switch to version 1.2.4. It worked for me

Just gave it a try. It throws the same error. Did you install it using the repository or using the command: pip install mmcv-full==1.2.4

kapil-varshney commented 3 years ago

I am facing the same issue.

Python 3.7.10 (default, Feb 26 2021, 13:06:18) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from mmcv.ops import get_compiling_cuda_version, get_compiler_version
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\kap10429\tasks\32_mmdetection\mmcv\mmcv\ops\__init__.py", line 1, in <module>
    from .bbox import bbox_overlaps
  File "C:\Users\kap10429\tasks\32_mmdetection\mmcv\mmcv\ops\bbox.py", line 3, in <module>
    ext_module = ext_loader.load_ext('_ext', ['bbox_overlaps'])
  File "C:\Users\kap10429\tasks\32_mmdetection\mmcv\mmcv\utils\ext_loader.py", line 11, in load_ext
    ext = importlib.import_module('mmcv.' + name)
  File "C:\Users\kap10429\Anaconda3\envs\open-mmlab\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'mmcv._ext'

OS: Windows 10

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 461.09       Driver Version: 461.09       CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+

Steps to setup:

conda install pytorch==1.7.0 torchvision==0.8.0 cudatoolkit=11.0 -c pytorch
git clone https://github.com/open-mmlab/mmcv.git
cd mmcv
python -m pip install -e .

Please let me know if anyone has had success with Windows in regards to this issue.

Which version of mmcv-full are you using??

I am using the latest clone. It is v1.3.0

Switch to version 1.2.4. It worked for me

Just gave it a try. It throws the same error. Did you install it using the repository or using the command: pip install mmcv-full==1.2.4

KKhushhalR2405 commented 3 years ago

I am facing the same issue.

Python 3.7.10 (default, Feb 26 2021, 13:06:18) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from mmcv.ops import get_compiling_cuda_version, get_compiler_version
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\kap10429\tasks\32_mmdetection\mmcv\mmcv\ops\__init__.py", line 1, in <module>
    from .bbox import bbox_overlaps
  File "C:\Users\kap10429\tasks\32_mmdetection\mmcv\mmcv\ops\bbox.py", line 3, in <module>
    ext_module = ext_loader.load_ext('_ext', ['bbox_overlaps'])
  File "C:\Users\kap10429\tasks\32_mmdetection\mmcv\mmcv\utils\ext_loader.py", line 11, in load_ext
    ext = importlib.import_module('mmcv.' + name)
  File "C:\Users\kap10429\Anaconda3\envs\open-mmlab\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'mmcv._ext'

OS: Windows 10

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 461.09       Driver Version: 461.09       CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+

Steps to setup:

conda install pytorch==1.7.0 torchvision==0.8.0 cudatoolkit=11.0 -c pytorch
git clone https://github.com/open-mmlab/mmcv.git
cd mmcv
python -m pip install -e .

Please let me know if anyone has had success with Windows in regards to this issue.

Which version of mmcv-full are you using??

I am using the latest clone. It is v1.3.0

Switch to version 1.2.4. It worked for me

Just gave it a try. It throws the same error. Did you install it using the repository or using the command: pip install mmcv-full==1.2.4

I did it using pip. First, uninstall the previous version and then install 1.2.4.

kapil-varshney commented 3 years ago

I am facing the same issue.

Python 3.7.10 (default, Feb 26 2021, 13:06:18) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from mmcv.ops import get_compiling_cuda_version, get_compiler_version
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\kap10429\tasks\32_mmdetection\mmcv\mmcv\ops\__init__.py", line 1, in <module>
    from .bbox import bbox_overlaps
  File "C:\Users\kap10429\tasks\32_mmdetection\mmcv\mmcv\ops\bbox.py", line 3, in <module>
    ext_module = ext_loader.load_ext('_ext', ['bbox_overlaps'])
  File "C:\Users\kap10429\tasks\32_mmdetection\mmcv\mmcv\utils\ext_loader.py", line 11, in load_ext
    ext = importlib.import_module('mmcv.' + name)
  File "C:\Users\kap10429\Anaconda3\envs\open-mmlab\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'mmcv._ext'

OS: Windows 10

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 461.09       Driver Version: 461.09       CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+

Steps to setup:

conda install pytorch==1.7.0 torchvision==0.8.0 cudatoolkit=11.0 -c pytorch
git clone https://github.com/open-mmlab/mmcv.git
cd mmcv
python -m pip install -e .

Please let me know if anyone has had success with Windows in regards to this issue.

Which version of mmcv-full are you using??

I am using the latest clone. It is v1.3.0

Switch to version 1.2.4. It worked for me

Just gave it a try. It throws the same error. Did you install it using the repository or using the command: pip install mmcv-full==1.2.4

I did it using pip. First, uninstall the previous version and then install 1.2.4.

Yes, I tried the installation after uninstalling the prior version. Doesn't work. Also, the pip install command doesn't work for me with any version. It always throws an error that ends with:

ERROR: Command errored out with exit status 1: 'C:\Users\kap10429\Anaconda3\envs\open-mmlab\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\kap10429\\AppData\\Local\\Temp\\pip-install-2apabm9d\\mmcv-full_9f1445ddf4fe439aafe1823244d52eb0\\setup.py'"'"'; __file__='"'"'C:\\Users\\kap10429\\AppData\\Local\\Temp\\pip-install-2apabm9d\\mmcv-full_9f1445ddf4fe439aafe1823244d52eb0\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\kap10429\AppData\Local\Temp\pip-record-t2vi5h5r\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\kap10429\Anaconda3\envs\open-mmlab\Include\mmcv-full' Check the logs for full command output.

SamMohel commented 3 years ago

I am facing the same issue.

Python 3.7.10 (default, Feb 26 2021, 13:06:18) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from mmcv.ops import get_compiling_cuda_version, get_compiler_version
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\kap10429\tasks\32_mmdetection\mmcv\mmcv\ops\__init__.py", line 1, in <module>
    from .bbox import bbox_overlaps
  File "C:\Users\kap10429\tasks\32_mmdetection\mmcv\mmcv\ops\bbox.py", line 3, in <module>
    ext_module = ext_loader.load_ext('_ext', ['bbox_overlaps'])
  File "C:\Users\kap10429\tasks\32_mmdetection\mmcv\mmcv\utils\ext_loader.py", line 11, in load_ext
    ext = importlib.import_module('mmcv.' + name)
  File "C:\Users\kap10429\Anaconda3\envs\open-mmlab\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'mmcv._ext'

OS: Windows 10

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 461.09       Driver Version: 461.09       CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+

Steps to setup:

conda install pytorch==1.7.0 torchvision==0.8.0 cudatoolkit=11.0 -c pytorch
git clone https://github.com/open-mmlab/mmcv.git
cd mmcv
python -m pip install -e .

Please let me know if anyone has had success with Windows in regards to this issue.

Which version of mmcv-full are you using??

I am using the latest clone. It is v1.3.0

Switch to version 1.2.4. It worked for me

Just gave it a try. It throws the same error. Did you install it using the repository or using the command: pip install mmcv-full==1.2.4

I did it using pip. First, uninstall the previous version and then install 1.2.4.

Yes, I tried the installation after uninstalling the prior version. Doesn't work. Also, the pip install command doesn't work for me with any version. It always throws an error that ends with:

ERROR: Command errored out with exit status 1: 'C:\Users\kap10429\Anaconda3\envs\open-mmlab\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\kap10429\\AppData\\Local\\Temp\\pip-install-2apabm9d\\mmcv-full_9f1445ddf4fe439aafe1823244d52eb0\\setup.py'"'"'; __file__='"'"'C:\\Users\\kap10429\\AppData\\Local\\Temp\\pip-install-2apabm9d\\mmcv-full_9f1445ddf4fe439aafe1823244d52eb0\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\kap10429\AppData\Local\Temp\pip-record-t2vi5h5r\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\kap10429\Anaconda3\envs\open-mmlab\Include\mmcv-full' Check the logs for full command output.

did you solve it ?

surendrallam commented 3 years ago

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

SamMohel commented 3 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](https://github.com/open-mmlab/mmdetection/blob/master/docs/get_started.md)
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 smiley
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

i have cuda 11.0 and tried your solution and got f'MMCV=={mmcv.__version__} is used but incompatible. ' \ AssertionError: MMCV==1.3.1 is used but incompatible. Please install mmcv>=1.2.4, <=1.3.

THEBEST-cloud commented 3 years ago

I run the MMCV_WITH_OPS=1 pip install -e . and then solve the problem just wait when running setup.py develop for mmcv-full

How do you run MMCV_WITH_OPS=1 pip install -e . I can not run it

nikhilbyte commented 3 years ago

I run the MMCV_WITH_OPS=1 pip install -e . and then solve the problem just wait when running setup.py develop for mmcv-full

How do you run MMCV_WITH_OPS=1 pip install -e . I can not run it

MMCV_WITH_OPS=1 pip install -e .

azmathmoosa commented 3 years ago

What I found useful was to first install mmcv pip install mmcv

then run the collect_env.py script

$ python mmdet/utils/collect_env.py

sys.platform: linux
Python: 3.7.10 (default, Feb 26 2021, 18:47:35) [GCC 7.3.0]
CUDA available: True
GPU 0: GeForce RTX 2070 with Max-Q Design
CUDA_HOME: /usr/local/cuda-10.2
NVCC: Cuda compilation tools, release 10.2, V10.2.89
GCC: gcc (Ubuntu 8.4.0-3ubuntu2) 8.4.0
PyTorch: 1.8.1
PyTorch compiling details: PyTorch built with:
  - GCC 7.3
  - C++ Version: 201402
  - Intel(R) oneAPI Math Kernel Library Version 2021.2-Product Build 20210312 for Intel(R) 64 architecture applications
  - Intel(R) MKL-DNN v1.7.0 (Git Hash 7aed236906b1f7a05c0917e5257a1af05e9ff683)
  - OpenMP 201511 (a.k.a. OpenMP 4.5)
  - NNPACK is enabled
  - CPU capability usage: AVX2
  - CUDA Runtime 10.2
  - NVCC architecture flags: -gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_61,code=sm_61;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_37,code=compute_37
  - CuDNN 7.6.5
  - Magma 2.5.2
  - Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=10.2, CUDNN_VERSION=7.6.5, CXX_COMPILER=/opt/rh/devtoolset-7/root/usr/bin/c++, CXX_FLAGS= -Wno-deprecated -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -fopenmp -DNDEBUG -DUSE_KINETO -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -O2 -fPIC -Wno-narrowing -Wall -Wextra -Werror=return-type -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-unused-local-typedefs -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-psabi -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Wno-stringop-overflow, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_VERSION=1.8.1, USE_CUDA=ON, USE_CUDNN=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=ON, USE_NNPACK=ON, USE_OPENMP=ON, 

TorchVision: 0.9.1
OpenCV: 4.5.2
MMCV: 1.3.5
MMCV Compiler: n/a
MMCV CUDA Compiler: n/a
MMDetection: 2.12.0+2d6b8e9

After that just copy the cuda, and torch versions. Then uninstall mmcv and then install mmcv-full like so

pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu{cuda_version}/torch{pytroch version}/index.html

For me it was: pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu102/torch1.8.1/index.html

If you have multiple cuda versions installed, then you need to select the cuda version that pytorch was built with - it said 10.2 for me, so I had to export CUDA_HOME=/usr/local/cuda-10.2 before the pip install command and it worked.

franva commented 3 years ago

had the same issue.

Uninstalled the mmcv, installed mmcv-full==1.3.0 and it starts working

THEBEST-cloud commented 3 years ago

OK Thanks

------------------ 原始邮件 ------------------ 发件人: "open-mmlab/mmdetection" @.>; 发送时间: 2021年8月18日(星期三) 晚上8:52 @.>; @.**@.>; 主题: Re: [open-mmlab/mmdetection] ModuleNotFoundError: No module named 'mmcv._ext' (#3271)

had the same issue.

Uninstalled the mmcv, installed mmcv-full==1.3.0 and it starts working

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.