linux安装 pycocotools_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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值