Windows下安装 pycocotools

windows下安装pycocotools包时,遇到了一大堆坑,这篇文章希望能让大家少走一点弯路。pycocotools作者压根就没考虑windows版本。

  • 安装pycocotools

COCO 地址: https://github.com/cocodataset/cocoapi
大佬改写支持 Windows 的 COCO 地址:https://github.com/philferriere/cocoapi

方案一

CMD 终端中使用 pip 安装:

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

方案二

https://github.com/philferriere/cocoapi下载源码,并进行解压。以管理员身份打开 CMD 终端,并切换到 cocoapi\PythonAPI目录。运行以下指令:

# install pycocotools locally
python setup.py build_ext --inplace
 
# install pycocotools to the Python site-packages
python setup.py build_ext install

  • 附:安装遇到的问题

1、安装环境问题

error: command 'cl.exe' failed: No such file or directory
// 或者
error: Unable to find vcvarsall.bat
// 或者
error: Microsoft Visual C++ 14.0 is required.
13068476-fd34bcc230e46425.png
error: command 'cl.exe' failed: No such file or directory
13068476-b9a1c847c72016de.png
pip install git+https://github.com/philferriere/cocoapi.git#subdir

因为没有Visual C++ 编译环境。解决方式:
安装Build Tools for Visual Studio 2017 (2015版及以后就行,不需要安装整个vs)


13068476-7b7cca0a76646238.png
vs2015

2、Wno-cpp和Wno-unused-function问题

cl: 命令行 error D8021 :无效的数值参数“/Wno-cpp” 和 cl: 命令行 error D8021 :无效的数值参数“/Wno-unused-function

解决方式: 删除cocoapi\PythonAPI\setup.py里的Wno-cpp和Wno-unused-function参数。

13068476-6618ef3135277c23.png
删除Wno-cpp参数

猜你喜欢

转载自blog.csdn.net/weixin_34138521/article/details/90818353