open-mmlab / mmsegmentation

OpenMMLab Semantic Segmentation Toolbox and Benchmark.
https://mmsegmentation.readthedocs.io/en/main/
Apache License 2.0
8.33k stars 2.63k forks source link

pyinstaller error : ModuleNotFoundError: No module named 'mmcv._ext' #854

Closed wongyufei closed 3 years ago

wongyufei commented 3 years ago

The plantform is win10, I install mmcv-full 1.1.5 for mmseg. It works well when I run main.py in pycharm. However, after using pyinstaller package it a exe. It wrongs! ModuleNotFoundError: No module named 'mmcv._ext'

Here are the details:

Traceback (most recent call last): File "main.py", line 15, in File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module File "mmseg\apis__init.py", line 1, in File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module File "mmseg\apis\inference.py", line 8, in File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module File "mmseg\models\init.py", line 1, in File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module File "mmseg\models\backbones\init.py", line 2, in File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module File "mmseg\models\backbones\fast_scnn.py", line 7, in File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module File "mmseg\models\decode_heads\init.py", line 16, in File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module File "mmseg\models\decode_heads\point_head.py", line 6, in File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module File "mmcv\ops\init.py", line 1, in File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module File "mmcv\ops\bbox.py", line 3, in File "mmcv\utils\ext_loader.py", line 11, in load_ext File "importlib\init__.py", line 126, in import_module ModuleNotFoundError: No module named 'mmcv._ext'

MengzhangLI commented 3 years ago

Hi, I guess it is caused by version conflict between MMSegmentation and MMCV or installation failure of MMCV.

Please check out here: https://github.com/open-mmlab/mmdetection/issues/3765, https://github.com/open-mmlab/mmdetection/issues/3271

I suggest you uninstall MMCV and install correct MMCV-full again.

Best,

wongyufei commented 3 years ago

I install mmcv-full==1.1.5 mmsegmentation==0.12.0, I think it is reasonable. It works well when I run this code with pycharm, but it wrong after using pyinstaller pack it up.

MengzhangLI commented 3 years ago

I install mmcv-full==1.1.5 mmsegmentation==0.12.0, I think it is reasonable. It works well when I run this code with pycharm, but it wrong after using pyinstaller pack it up.

OK, does it works well if you use terminal ?

wongyufei commented 3 years ago

Yes,it works well

MengzhangLI commented 3 years ago

OK, I will write down this issue and discuss with my colleagues.

Because it has something to do with PyInstaller, which beyond codebase itself, please wait for a couple of days.

Best,

wongyufei commented 3 years ago

Thanks for your reply!

MengzhangLI commented 3 years ago

Hi, did you check whether the environment is the same? I mean the pyinstaller uses same environment with terminal and pycharm?

wongyufei commented 3 years ago

I use anaconda build a new virtual env. And the pyinstaller is also installed in this env. I run main.py  code in this virtual env. and use pyinstaller in this virtual env.

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2021年9月8日(星期三) 中午11:55 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [open-mmlab/mmsegmentation] pyinstaller error : ModuleNotFoundError: No module named 'mmcv._ext' (#854)

Hi, did you check whether the environment is the same? I mean the pyinstaller uses same environment with terminal and pycharm?

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

MengzhangLI commented 3 years ago

OK, got it. Please wait for some days.

Best,

yldcs commented 3 years ago

I got the same problem. Do you have fixed it ?

wongyufei commented 3 years ago

No,I try to use cx_Freeze to pack the main.py. But it cannot load PyQt5 correctly.

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2021年9月8日(星期三) 下午5:43 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [open-mmlab/mmsegmentation] pyinstaller error : ModuleNotFoundError: No module named 'mmcv._ext' (#854)

I got the same problem. Did have fixed it ?

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

majnas commented 3 years ago

Package Version Location


addict 2.4.0
cycler 0.10.0
kiwisolver 1.3.2
matplotlib 3.4.3
mmcv 1.3.12
mmcv-full 1.3.12
mmsegmentation 0.17.0 /mnt/project//semantic_segmentation/code/mmsegmentation numpy 1.21.2
opencv-python 4.5.3.56 packaging 21.0
Pillow 8.3.2
pip 20.0.2
pkg-resources 0.0.0
prettytable 2.2.0
pyparsing 2.4.7
python-dateutil 2.8.2
PyYAML 5.4.1
setuptools 44.0.0
six 1.16.0
torch 1.8.1
torchaudio 0.8.1
torchvision 0.9.1
typing-extensions 3.10.0.2 wcwidth 0.2.5
wheel 0.34.2
yapf 0.31.0

after changing mmcv-full from 1.3.7 to 1.3.12 problem solved!

pip uninstall mmcv pip uninstall mmcv-full pip install mmcv-full==1.3.12 pip install mmcv

wongyufei commented 3 years ago

after changing mmcv-full from 1.3.7 to 1.3.12, the problem is still exists. Probably my problem is different from yours. Thanks for your reply!

------------------ 原始邮件 ------------------ 发件人: "majid @.>; 发送时间: 2021年9月9日(星期四) 下午3:04 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [open-mmlab/mmsegmentation] pyinstaller error : ModuleNotFoundError: No module named 'mmcv._ext' (#854)

Package Version Location

addict 2.4.0 cycler 0.10.0 kiwisolver 1.3.2 matplotlib 3.4.3 mmcv 1.3.12 mmcv-full 1.3.12 mmsegmentation 0.17.0 /mnt/project//semantic_segmentation/code/mmsegmentation numpy 1.21.2 opencv-python 4.5.3.56 packaging 21.0 Pillow 8.3.2 pip 20.0.2 pkg-resources 0.0.0 prettytable 2.2.0 pyparsing 2.4.7 python-dateutil 2.8.2 PyYAML 5.4.1 setuptools 44.0.0 six 1.16.0 torch 1.8.1 torchaudio 0.8.1 torchvision 0.9.1 typing-extensions 3.10.0.2 wcwidth 0.2.5 wheel 0.34.2 yapf 0.31.0

after changing mmcv-full from 1.3.7 to 1.3.12 problem solved!

pip uninstall mmcv pip uninstall mmcv-full pip install mmcv-full==1.3.12 pip install mmcv

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

maisonhai3 commented 2 years ago

Try this command: pyinstaller --hidden-import=mmcv._ext --hidden-import torchvision --onefile our_python_file.py

Explain

We faced this issue exactly. Here my collage solution:

Our platform:

If you want to package with PyTorch GPU version, I am not sure if this method works, but worth a try.

wongyufei commented 2 years ago

Thanks for your reply!

------------------ 原始邮件 ------------------ 发件人: "open-mmlab/mmsegmentation" @.>; 发送时间: 2021年12月7日(星期二) 上午10:03 @.>; @.**@.>; 主题: Re: [open-mmlab/mmsegmentation] pyinstaller error : ModuleNotFoundError: No module named 'mmcv._ext' (#854)

We faced this issue exactly. Here my collage solution:

While running pyinstaller, add --hidden-import with the path to your mmcv

While install PyTorch, we only want to use CPU version, so in homepage of PyTorch, we use pip-cpu-version install command. Then, this solution worked. Our platform:

Windows 11,

GPU 1080Ti.

Anaconda

If you want to package with PyTorch GPU version, I am not sure if this method works, but worth a try.

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

wydonglove commented 1 year ago

@wongyufei @MengzhangLI Do you have fixed it ? thanks for your reply

xiehou-design commented 1 year ago

I also meet this problem. Do you have fix it? Thanks.