Windows安装pycocotools无法解决方法(采坑笔记)

当你在Windows下执行Tensorflow object_detection的脚本时会报错,
这时因为object_detection下面默认是没有包含cocotools的python实现代码的,Anaconda默认也没提供这个库,需要安装pycocotools,但如果你执行: python -m pip install pycocotools时
又会报错。
ERROR: Command errored out with exit status 1:
command: 'D:\Anaconda3\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\46653\\AppData\\Local\\Temp\\pip-install-j33342g5\\pycocotools\\setup.py'"'"'; __file__='"'"'C:\\Users\\46653\\AppData\\Local\\Temp\\pip-install-j33342g5\\pycocotools\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\46653\AppData\Local\Temp\pip-wheel-0xpeseyp' --python-tag cp37
cwd: C:\Users\46653\AppData\Local\Temp\pip-install-j33342g5\pycocotools\
Complete output (13 lines):
running bdist_wheel
running build
running build_py
creating build
creating build\lib.win-amd64-3.7
creating build\lib.win-amd64-3.7\pycocotools
copying pycocotools\coco.py -> build\lib.win-amd64-3.7\pycocotools
copying pycocotools\cocoeval.py -> build\lib.win-amd64-3.7\pycocotools
copying pycocotools\mask.py -> build\lib.win-amd64-3.7\pycocotools
copying pycocotools\__init__.py -> build\lib.win-amd64-3.7\pycocotools
running build_ext
building 'pycocotools._mask' extension
error: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/
----------------------------------------
ERROR: Failed building wheel for pycocotools
ERROR: Command errored out with exit status 1:
command: 'D:\Anaconda3\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\46653\\AppData\\Local\\Temp\\pip-install-j33342g5\\pycocotools\\setup.py'"'"'; __file__='"'"'C:\\Users\\46653\\AppData\\Local\\Temp\\pip-install-j33342g5\\pycocotools\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\46653\AppData\Local\Temp\pip-record-ucmhdqzv\install-record.txt' --single-version-externally-managed --compile
cwd: C:\Users\46653\AppData\Local\Temp\pip-install-j33342g5\pycocotools\
Complete output (13 lines):
running install
running build
running build_py
creating build
creating build\lib.win-amd64-3.7
creating build\lib.win-amd64-3.7\pycocotools
copying pycocotools\coco.py -> build\lib.win-amd64-3.7\pycocotools
copying pycocotools\cocoeval.py -> build\lib.win-amd64-3.7\pycocotools
copying pycocotools\mask.py -> build\lib.win-amd64-3.7\pycocotools
copying pycocotools\__init__.py -> build\lib.win-amd64-3.7\pycocotools
running build_ext
building 'pycocotools._mask' extension
error: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/
----------------------------------------
ERROR: Command errored out with exit status 1: 'D:\Anaconda3\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\46653\\AppData\\Local\\Temp\\pip-install-j33342g5\\pycocotools\\setup.py'"'"'; __file__='"'"'C:\\Users\\46653\\AppData\\Local\\Temp\\pip-install-j33342g5\\pycocotools\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\46653\AppData\Local\Temp\pip-record-ucmhdqzv\install-record.txt' --single-version-externally-managed --compile Check the logs for full command output.
这说明你的Windows下没有c/c++代码编译环境(因为pycocotools的主站点源码https://github.com/cocodataset/cocoapi默认只提供了源码,没有针对各平台编译好了的release,而且声称将来不支持Windows! ),这个不是简单安装个MS VC就行了(你会发现安装了还是报这个错),需要到这里下载visualcppbuildtools_full.exe来安装(下载地址在文章末尾或者点击https://go.microsoft.com/fwlink/?LinkId=691126下载)。
这是因为pip安装默认下载的源码是不支持Windows上编译的,需要从一个让pycocotools PythonAPI支持使用Windows和Python 3 来build的clone站点https://github.com/philferriere/cocoapi来安装,执行下面的命令:

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

直接pip安装的pycocotools支持windows 需要下载支持windows的版本来安装
执行
pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
如果安装完成会显示如下成功界面。

如果安装完成找不到 ‘rc.exe’请执行下面步骤
已经安装好buildTools 开始报这个错 (之前缺少VS14.0, python3.7的确没有)
如下:
1、将C:\Program Files (x86)\Windows Kits\8.1\bin\x64 加入环境变量
2、从C:\Program Files (x86)\Windows Kits\8.1\bin\x86 里复制rc.exe rcdll.dll 这两个文件到C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin 目录下
最后搞定!!

「点点赞赏,手留余香」

    还没有人赞赏,快来当第一个赞赏的人吧!
0 条回复 A 作者 M 管理员
    所有的伟大,都源于一个勇敢的开始!
欢迎您,新朋友,感谢参与互动!欢迎您 {{author}},您在本站有{{commentsCount}}条评论
TrustAsia 安全签章 阿里云WordPress

Optimized by WPJAM Basic