刚安装完pycocotools,整理一下我遇到的问题。
一:克隆
- cocoapi来自于github https://github.com/pdollar/coco ,从github上clone即可。
git clone https://github.com/pdollar/coco
如果你看到上面这段话,不要直接进行克隆安装。这里提醒一下,使用git,要先按转Git。我当时是直接克隆的,然后后续会出现windows下 cl: 命令行 error D8021 :无效的数值参数“/Wno-cpp”
这个错误,据说是因为pycocotools不支持windows。
所以windows安装的话可以克隆安装这个版本https://github.com/philferriere/cocoapi
参考链接:https://blog.csdn.net/heiheiya/article/details/81128749
二:安装
之后进入到安装目录下,进行安装。如果是conda虚拟环境,就在anaconda prompt下进入安装目录,都是执行python 安装,这取决于你之后使用什么编译器。安装命令和安装目录如下:
(tensorflow) C:\Users\skwang\cocoapi\PythonAPI>python setup.py install
安装完后,可能会出现提示
:error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools
那就按照它的提示进入安装https://visualstudio.microsoft.com/zh-hans/visual-cpp-build-tools/
记得之后要选择自己需要的C++ Build Tools。
三:
最后的报错应该就是Cython的报错了,这个直接安装就完事了,anaconda就是conda install cython
,python就是 pip install cython
Traceback (most recent call last):
File "setup.py", line 2, in <module>
from Cython.Build import cythonize
ModuleNotFoundError: No module named 'Cython'
之后就安装成功啦!
其实这么多报错,要么是版本问题,要么是语言问题。因为pycocotools的主站点源码默认只提供了源码,没有针对各平台编译好了的release,所以我们也需要C++的工具。Cython也是一个快速生成Python扩展模块的工具,从语法层面上来讲是Python语法和C语言语法的混血。
还有部分问题可参考:https://codechina.csdn.net/mirrors/philferriere/cocoapi/-/tree/master/PythonAPI