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 目录下
最后搞定!!


已发布

分类

来自

标签:

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注