Could not install pycocotools in windows10

I am trying to install the cocoapi from this link: https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/install.html

I followed the instructions as given, but got stuck with the error shown below, I've tried a lot of solutions but nothing worked. Any help will be much appreciated.

I have tried the following commands:

$ pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
$ pip3 install "git+https://github.com/philferriere/cocoapi.git#egg=pycocotools&subdirectory=PythonAPI"

But for both commands, I get the following error:

ERROR: Command errored out with exit status 1:
     command: 'C:\Users\LENOVO\anaconda3\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\LENOVO\\AppData\\Local\\Temp\\pip-install-ohatcfil\\pycocotools_6b8d44b0841d4434ab4a95deb55f7d9a\\PythonAPI\\setup.py'"'"'; __file__='"'"'C:\\Users\\LENOVO\\AppData\\Local\\Temp\\pip-install-ohatcfil\\pycocotools_6b8d44b0841d4434ab4a95deb55f7d9a\\PythonAPI\\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\LENOVO\AppData\Local\Temp\pip-record-4ngej82s\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\LENOVO\anaconda3\Include\pycocotools'
         cwd: C:\Users\LENOVO\AppData\Local\Temp\pip-install-ohatcfil\pycocotools_6b8d44b0841d4434ab4a95deb55f7d9a\PythonAPI
    Complete output (6 lines):
    running install
    running build
    running build_py
    running build_ext
    building 'pycocotools._mask' extension
    error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'C:\Users\LENOVO\anaconda3\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\LENOVO\\AppData\\Local\\Temp\\pip-install-ohatcfil\\pycocotools_6b8d44b0841d4434ab4a95deb55f7d9a\\PythonAPI\\setup.py'"'"'; __file__='"'"'C:\\Users\\LENOVO\\AppData\\Local\\Temp\\pip-install-ohatcfil\\pycocotools_6b8d44b0841d4434ab4a95deb55f7d9a\\PythonAPI\\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\LENOVO\AppData\Local\Temp\pip-record-4ngej82s\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\LENOVO\anaconda3\Include\pycocotools' Check the logs for full command output.

Solution 1:

As the error says, in order to build pycocotools on a Windows system, you need to have additional C++ redistributables installed.

Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/