首页 > 解决方案 > ModuleNotFoundError:没有名为“pycocotools._mask”的模块

问题描述

我正在尝试从 cocoapi(https://github.com/cocodataset/cocoapi)训练 Mask-R CNN 模型,并且此错误代码不断出现。

    ModuleNotFoundError                       Traceback (most recent call last)
    <ipython-input-8-83356bb9cf95> in <module>
         19 sys.path.append(os.path.join(ROOT_DIR, "samples/coco/"))  # To find local version
         20 
    ---> 21 from pycocotools.coco import coco
         22 
         23 get_ipython().run_line_magic('matplotlib', 'inline ')

~/Desktop/coco/PythonAPI/pycocotools/coco.py in <module>
     53 import copy
     54 import itertools
---> 55 from . import mask as maskUtils
     56 import os
     57 from collections import defaultdict

~/Desktop/coco/PythonAPI/pycocotools/mask.py in <module>
      1 __author__ = 'tsungyi'
      2 
----> 3 import pycocotools._mask as _mask
      4 
      5 # Interface for manipulating masks stored in RLE format.

ModuleNotFoundError: No module named 'pycocotools._mask'

我尝试了 github 'issues' 选项卡上的所有方法,但它对我根本不起作用。有没有另一种解决方案?我正在使用 Python 3.6,Linux。

标签: python-3.xmodulenotfounderror

解决方案


答案是从这 三个 GitHub 问题中总结出来的

1.是否安装了正确版本的cython。也就是说,如果你使用 python2/3,你应该为 python2/3 安装 cython

pip install cython

2.你是否从这个 github 项目下载了整个 .zip 文件。也就是说,即使你只需要 PythonAPI,你也应该在这里下载所有东西

git clone https://github.com/cocodataset/cocoapi.git

或者

解压压缩文件

3.是否打开终端并在正确的文件夹下运行“make”。正确的文件夹是“Makefile”所在的文件夹

cd path/to/coco/PythonAPI/Makefile
make

差不多,问题就可以解决了。

如果没有,4 和 5 可能会有所帮助。

4.是否已经安装了正确版本的gcc

5.是否已经安装了正确版本的python-dev。也就是说,如果你使用 python3,你应该安装 python3-dev(你可以尝试“sudo apt-get install python3-dev”)。


推荐阅读