windows10 pycocotools错误ModuleNotFoundError: No module named ‘_mask‘

whl下载:

Links for pycocotools-windows

上面的版本到python 3.8,那如果我的版本是python 3.10就有点难办,要么装不上,要么装上了不能用,装不上是因为安装的时候编译源码到whl出错,装上了不能用是因为你的pycocotools相关依赖不对,下面说下我探索的过程。

windows在使用pycocotools时总遇到奇怪的问题,明明用whl装上的时候没报错,使用的时候就出现各种错误,比如下面的:ModuleNotFoundError: No module named '_mask'

Traceback (most recent call last):
  File "G:\Github\mmdetection-main\demo\image_demo.py", line 29, in <module>
    from mmdet.apis import DetInferencer
  File "g:\github\mmdetection-main\mmdet\apis\__init__.py", line 2, in <module>
    from .det_inferencer import DetInferencer
  File "g:\github\mmdetection-main\mmdet\apis\det_inferencer.py", line 21, in <module>
    from mmdet.evaluation import INSTANCE_OFFSET
  File "g:\github\mmdetection-main\mmdet\evaluation\__init__.py", line 3, in <module>
    from .metrics import *  # noqa: F401,F403
  File "g:\github\mmdetection-main\mmdet\evaluation\metrics\__init__.py", line 3, in <module>
    from .coco_metric import CocoMetric
  File "g:\github\mmdetection-main\mmdet\evaluation\metrics\coco_metric.py", line 16, in <module>
    from mmdet.datasets.api_wrappers import COCO, COCOeval
  File "g:\github\mmdetection-main\mmdet\datasets\__init__.py", line 3, in <module>
    from .cityscapes import CityscapesDataset
  File "g:\github\mmdetection-main\mmdet\datasets\cityscapes.py", line 8, in <module>
    from .coco import CocoDataset
  File "g:\github\mmdetection-main\mmdet\datasets\coco.py", line 9, in <module>
    from .api_wrappers import COCO
  File "g:\github\mmdetection-main\mmdet\datasets\api_wrappers\__init__.py", line 2, in <module>
    from .coco_api import COCO, COCOeval, COCOPanoptic
  File "g:\github\mmdetection-main\mmdet\datasets\api_wrappers\coco_api.py", line 9, in <module>
    from pycocotools.coco import COCO as _COCO
  File "F:\Anaconda3\envs\pt310\lib\site-packages\pycocotools\coco.py", line 55, in <module>
    from . import mask as maskUtils
  File "F:\Anaconda3\envs\pt310\lib\site-packages\pycocotools\mask.py", line 4, in <module>
    import _mask as _mask
ModuleNotFoundError: No module named '_mask'

windows如果直接pip install pycocotools无法安装说明其它依赖的版本不对,比如在python3.10下安装pycocotools2.0.0.4时,先把以前pycocotools_windows-2.0.0.2-cp38-cp38-win_amd64.whl 改为pycocotools_windows-2.0.0.2-cp310-cp310-win_amd64.whl,这时pip会找3.10下2.0.0.2的依赖,那么2.0.0.2和2.0.0.4的依赖其实相差不多。此时就知道2.0.0.4依赖了什么,并且也安装上了

Requirement already satisfied: setuptools>=18.0 in f:\anaconda3\envs\pt310\lib\site-packages (from pycocotools-windows==2.0.0.2) (63.4.1)
Requirement already satisfied: cython>=0.27.3 in f:\anaconda3\envs\pt310\lib\site-packages (from pycocotools-windows==2.0.0.2) (0.29.34)
Requirement already satisfied: matplotlib>=2.1.0 in f:\anaconda3\envs\pt310\lib\site-packages (from pycocotools-windows==2.0.0.2) (3.5.3)
Requirement already satisfied: pillow>=6.2.0 in f:\anaconda3\envs\pt310\lib\site-packages (from matplotlib>=2.1.0->pycocotools-windows==2.0.0.2) (9.2.0)
Requirement already satisfied: pyparsing>=2.2.1 in f:\anaconda3\envs\pt310\lib\site-packages (from matplotlib>=2.1.0->pycocotools-windows==2.0.0.2) (3.0.9)
Requirement already satisfied: packaging>=20.0 in f:\anaconda3\envs\pt310\lib\site-packages (from matplotlib>=2.1.0->pycocotools-windows==2.0.0.2) (21.3)
Requirement already satisfied: numpy>=1.17 in f:\anaconda3\envs\pt310\lib\site-packages (from matplotlib>=2.1.0->pycocotools-windows==2.0.0.2) (1.24.3)
Requirement already satisfied: cycler>=0.10 in f:\anaconda3\envs\pt310\lib\site-packages (from matplotlib>=2.1.0->pycocotools-windows==2.0.0.2) (0.11.0)
Requirement already satisfied: kiwisolver>=1.0.1 in f:\anaconda3\envs\pt310\lib\site-packages (from matplotlib>=2.1.0->pycocotools-windows==2.0.0.2) (1.4.4)
Requirement already satisfied: fonttools>=4.22.0 in f:\anaconda3\envs\pt310\lib\site-packages (from matplotlib>=2.1.0->pycocotools-windows==2.0.0.2) (4.37.1)
Requirement already satisfied: python-dateutil>=2.7 in f:\anaconda3\envs\pt310\lib\site-packages (from matplotlib>=2.1.0->pycocotools-windows==2.0.0.2) (2.8.2)
Requirement already satisfied: six>=1.5 in f:\anaconda3\envs\pt310\lib\site-packages (from python-dateutil>=2.7->matplotlib>=2.1.0->pycocotools-windows==2.0.0.2) (1.16.0)
pycocotools-windows is already installed with the same version as the provided wheel. Use --force-reinstall to force an installation of the wheel.
(pt310) PS G:\Github\mmdetection-main> pip install C:\Users\MECHREVO\Downloads\pycocotools_windows-2.0.0.2-cp310-cp310-win_amd64.whl --force-reinstall
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Processing c:\users\mechrevo\downloads\pycocotools_windows-2.0.0.2-cp310-cp310-win_amd64.whl
Collecting cython>=0.27.3
  Downloading https://mirrors.aliyun.com/pypi/packages/d2/49/9845f14b6716614c832535b67e3b491434d7fdecf510fcb6fe254f60a974/Cython-0.29.34-py2.py3-none-any.whl (988 kB)
     ---------------------------------------- 988.1/988.1 kB 727.6 kB/s eta 0:00:00
Collecting setuptools>=18.0
  Downloading https://mirrors.aliyun.com/pypi/packages/2f/8c/f336a966d4097c7cef6fc699b2ecb83b5fb63fd698198c1b5c7905a74f0f/setuptools-67.7.2-py3-none-any.whl (1.1 MB)
     ---------------------------------------- 1.1/1.1 MB 624.7 kB/s eta 0:00:00
Collecting matplotlib>=2.1.0
  Downloading https://mirrors.aliyun.com/pypi/packages/07/76/fde990f131450f08eb06e50814b98d347b14d7916c0ec31cba0a65a9be2b/matplotlib-3.7.1-cp310-cp310-win_amd64.whl (7.6 MB)
     ---------------------------------------- 7.6/7.6 MB 657.9 kB/s eta 0:00:00
Collecting fonttools>=4.22.0
  Downloading https://mirrors.aliyun.com/pypi/packages/ad/5f/20da4f41e33e77723b0100ded6539529bd159319ed49d6459a4647cdc7ee/fonttools-4.39.4-py3-none-any.whl (1.0 MB)
     ---------------------------------------- 1.0/1.0 MB 744.4 kB/s eta 0:00:00
Collecting pillow>=6.2.0
  Downloading https://mirrors.aliyun.com/pypi/packages/3e/14/0030e542f2acfea43635e55584c114e6cfd94d342393a5f71f74c172dc35/Pillow-9.5.0-cp310-cp310-win_amd64.whl (2.5 MB)
     ---------------------------------------- 2.5/2.5 MB 690.0 kB/s eta 0:00:00
Collecting pyparsing>=2.3.1
  Downloading https://mirrors.aliyun.com/pypi/packages/6c/10/a7d0fa5baea8fe7b50f448ab742f26f52b80bfca85ac2be9d35cdd9a3246/pyparsing-3.0.9-py3-none-any.whl (98 kB)
     ---------------------------------------- 98.3/98.3 kB 624.8 kB/s eta 0:00:00
Collecting numpy>=1.20
  Downloading https://mirrors.aliyun.com/pypi/packages/65/5d/46da284b0bf6cfbf04082c3c5e84399664d69e41c11a33587ad49b0c64e5/numpy-1.24.3-cp310-cp310-win_amd64.whl (14.8 MB)
     ---------------------------------------- 14.8/14.8 MB 665.6 kB/s eta 0:00:00
Collecting kiwisolver>=1.0.1
  Downloading https://mirrors.aliyun.com/pypi/packages/68/20/2ce1186ef4edf47281faf58f6dd72a1fcd2be1fc66514bd2d220097bdcd1/kiwisolver-1.4.4-cp310-cp310-win_amd64.whl (55 kB)
     ---------------------------------------- 55.3/55.3 kB 577.2 kB/s eta 0:00:00
Collecting python-dateutil>=2.7
  Downloading https://mirrors.aliyun.com/pypi/packages/36/7a/87837f39d0296e723bb9b62bbb257d0355c7f6128853c78955f57342a56d/python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
     ---------------------------------------- 247.7/247.7 kB 690.3 kB/s eta 0:00:00
Collecting cycler>=0.10
  Downloading https://mirrors.aliyun.com/pypi/packages/5c/f9/695d6bedebd747e5eb0fe8fad57b72fdf25411273a39791cde838d5a8f51/cycler-0.11.0-py3-none-any.whl (6.4 kB)
Collecting contourpy>=1.0.1
  Downloading https://mirrors.aliyun.com/pypi/packages/b6/b8/6894c9e851f7442ebbc054537f56021c9ebc0691799ac4b92e380f3a2712/contourpy-1.0.7-cp310-cp310-win_amd64.whl (162 kB)
     ---------------------------------------- 163.0/163.0 kB 611.0 kB/s eta 0:00:00
Collecting packaging>=20.0
  Downloading https://mirrors.aliyun.com/pypi/packages/ab/c3/57f0601a2d4fe15de7a553c00adbc901425661bf048f2a22dfc500caf121/packaging-23.1-py3-none-any.whl (48 kB)
     ---------------------------------------- 48.9/48.9 kB 822.7 kB/s eta 0:00:00
Collecting six>=1.5
  Downloading https://mirrors.aliyun.com/pypi/packages/d9/5a/e7c31adbe875f2abbb91bd84cf2dc52d792b5a01506781dbcf25c91daf11/six-1.16.0-py2.py3-none-any.whl (11 kB)
Installing collected packages: six, setuptools, pyparsing, pillow, packaging, numpy, kiwisolver, fonttools, cython, cycler, python-dateutil, contourpy, matplotlib, pycocotools-windows
  Attempting uninstall: six
    Found existing installation: six 1.16.0
    Uninstalling six-1.16.0:
      Successfully uninstalled six-1.16.0
  Attempting uninstall: setuptools
    Found existing installation: setuptools 63.4.1
    Uninstalling setuptools-63.4.1:
      Successfully uninstalled setuptools-63.4.1
  Attempting uninstall: pyparsing
    Found existing installation: pyparsing 3.0.9
    Uninstalling pyparsing-3.0.9:
      Successfully uninstalled pyparsing-3.0.9
  Attempting uninstall: pillow
    Found existing installation: Pillow 9.2.0
    Uninstalling Pillow-9.2.0:
      Successfully uninstalled Pillow-9.2.0
  Attempting uninstall: packaging
    Found existing installation: packaging 21.3
    Uninstalling packaging-21.3:
      Successfully uninstalled packaging-21.3
  Attempting uninstall: numpy
    Found existing installation: numpy 1.24.3
    Uninstalling numpy-1.24.3:
      Successfully uninstalled numpy-1.24.3
  Attempting uninstall: kiwisolver
    Found existing installation: kiwisolver 1.4.4
    Uninstalling kiwisolver-1.4.4:
      Successfully uninstalled kiwisolver-1.4.4
  Attempting uninstall: fonttools
    Found existing installation: fonttools 4.37.1
    Uninstalling fonttools-4.37.1:
      Successfully uninstalled fonttools-4.37.1
  Attempting uninstall: cython
    Found existing installation: Cython 0.29.34
    Uninstalling Cython-0.29.34:
      Successfully uninstalled Cython-0.29.34
  Attempting uninstall: cycler
    Found existing installation: cycler 0.11.0
    Uninstalling cycler-0.11.0:
      Successfully uninstalled cycler-0.11.0
  Attempting uninstall: python-dateutil
    Found existing installation: python-dateutil 2.8.2
    Uninstalling python-dateutil-2.8.2:
      Successfully uninstalled python-dateutil-2.8.2
  Attempting uninstall: matplotlib
    Found existing installation: matplotlib 3.5.3
    Uninstalling matplotlib-3.5.3:
      Successfully uninstalled matplotlib-3.5.3
  Attempting uninstall: pycocotools-windows
    Found existing installation: pycocotools-windows 2.0.0.2
    Uninstalling pycocotools-windows-2.0.0.2:
      Successfully uninstalled pycocotools-windows-2.0.0.2
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
mmdet 3.0.0 requires pycocotools, which is not installed.
torchvision 0.13.1 requires torch==1.12.1, but you have torch 2.0.0 which is incompatible.
Successfully installed contourpy-1.0.7 cycler-0.11.0 cython-0.29.34 
fonttools-4.39.4 kiwisolver-1.4.4 matplotlib-3.7.1 numpy-1.24.3 
packaging-23.1 pillow-9.5.0 pycocotools-windows-2.0.0.2 
pyparsing-3.0.9 python-dateutil-2.8.2 setuptools-67.7.2 six-1.16.0

等上面安装完毕,再继续试试pip install pycocotools==2.0.4,此时的输出为:

Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting pycocotools==2.0.4
  Downloading https://mirrors.aliyun.com/pypi/packages/75/5c/ac61ea715d7a89ecc31c090753bde28810238225ca8b71778dfe3e6a68bc/pycocotools-2.0.4.tar.gz (106 kB)
     ---------------------------------------- 106.6/106.6 kB 771.1 kB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: numpy in f:\anaconda3\envs\pt310\lib\site-packages (from pycocotools==2.0.4) (1.24.3)
Requirement already satisfied: matplotlib>=2.1.0 in f:\anaconda3\envs\pt310\lib\site-packages (from pycocotools==2.0.4) (3.7.1)
Requirement already satisfied: pyparsing>=2.3.1 in f:\anaconda3\envs\pt310\lib\site-packages (from matplotlib>=2.1.0->pycocotools==2.0.4) (3.0.9)
Requirement already satisfied: kiwisolver>=1.0.1 in f:\anaconda3\envs\pt310\lib\site-packages (from matplotlib>=2.1.0->pycocotools==2.0.4) (1.4.4)
Requirement already satisfied: packaging>=20.0 in f:\anaconda3\envs\pt310\lib\site-packages (from matplotlib>=2.1.0->pycocotools==2.0.4) (23.1)
Requirement already satisfied: cycler>=0.10 in f:\anaconda3\envs\pt310\lib\site-packages (from matplotlib>=2.1.0->pycocotools==2.0.4) (0.11.0)
Requirement already satisfied: fonttools>=4.22.0 in f:\anaconda3\envs\pt310\lib\site-packages (from matplotlib>=2.1.0->pycocotools==2.0.4) (4.39.4)
Requirement already satisfied: python-dateutil>=2.7 in f:\anaconda3\envs\pt310\lib\site-packages (from matplotlib>=2.1.0->pycocotools==2.0.4) (2.8.2)
Requirement already satisfied: pillow>=6.2.0 in f:\anaconda3\envs\pt310\lib\site-packages (from matplotlib>=2.1.0->pycocotools==2.0.4) (9.5.0)
Requirement already satisfied: contourpy>=1.0.1 in f:\anaconda3\envs\pt310\lib\site-packages (from matplotlib>=2.1.0->pycocotools==2.0.4) (1.0.7)
Requirement already satisfied: six>=1.5 in f:\anaconda3\envs\pt310\lib\site-packages (from python-dateutil>=2.7->matplotlib>=2.1.0->pycocotools==2.0.4) (1.16.0)
Building wheels for collected packages: pycocotools
  Building wheel for pycocotools (pyproject.toml) ... done
  Created wheel for pycocotools: filename=pycocotools-2.0.4-cp310-cp310-win_amd64.whl size=75360 sha256=e5da07c221f1e750c9b7f97e2fa3cdf4fc5e5da2884cfa372b9e6146b6b4beff
  Stored in directory: c:\users\mechrevo\appdata\local\pip\cache\wheels\c2\43\74\632c7fc5e18e7f88962dd0f3d15c6f1297b6665983b9cd1ebe
Successfully built pycocotools
Installing collected packages: pycocotools
Successfully installed pycocotools-2.0.4

这个时候相关依赖都对了,那么在编译时(Building wheel)就不会报错了,装上以后也没有一开始ModuleNotFoundError: No module named '_mask'那个错误了,顺利使用。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

如雾如电

随缘

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值