------------------更新------------------
似乎有好心人专门给windows构建了pycocotools,此消息来自StackOverflow上的回答:
pip uninstall pycocotools
pip install pycocotools-windows
-----------------------------
因为pycocotools 的pypi不支持windows,所以我们不能在windows上通过pip install pycocotools来安装pycocotools。
我是这么在我的windows上安装pycocotools的:
1. 首先请确保你的电脑中已经装上了Visual C++ 2015 build tools,没有的话在这里下载。
下载好后如下图所示进行安装:
因为我不开发windows啥的,那些SDK就不安装了,能省一点磁盘空间就省一点。安装好后能在控制面板里看到下图的样子
---------------------------
2. 去https://github.com/philferriere/cocoapi把这个repo下载下来。
3. 打开命令行工具cmd或anaconda prompt,cd到cocoapi-master\PythonAPI里面,依次执行下面两条命令:
python setup.py build_ext --inplace # install pycocotools locally
python setup.py build_ext install # install pycocotools to the Python site-packages
按理说,你会看到下图的结果:
4. 之后你输入conda list,就能看到安装好的pycocotools了:
你还可以进入python输入下面语句试试:
import pycocotools.mask as cocomask
题外话
后来我在新电脑上重新安装pycocotools,在安装完 Visual C++ 2015 build tools 之后,接着执行
pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
本以为安装成功了,没想到训练时遇到了问题:
File "pycocotools/_mask.pyx", line 1, in init pycocotools._mask
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header
最后是通过文章开头更新说的:
pip uninstall pycocotools
pip install pycocotools-windows
解决。