【Python】安装pycocotools错误

错误信息

ImportError: No module named ‘pycocotools’

error: command ‘C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe’ failed with exit status 2

error: Microsoft Visual C++ 14.0 is required. Get it with “Microsoft Visual C++ Build Tools”: http://landinghub.visualstudio.com/visual-cpp-build-tools

ModuleNotFoundError: No module named ‘Cython’

解决方法

  1. pycocotools安装需要Visual C++ Build Tools,可以在https://visualstudio.microsoft.com/visual-cpp-build-tools/ 下载,原错误信息给出的链接已经失效了

  2. 除此之外,还需要安装Cython,直接pip即可

  3. 在Linux, 运行:

pip install git+https://github.com/waleedka/cocoapi.git#egg=pycocotools&subdirectory=PythonAPI

在Windows, 运行:

pip install git+https://github.com/philferriere/cocoapi.git#egg=pycocotools^&subdirectory=PythonAPI

Reference: https://github.com/matterport/Mask_RCNN/issues/6