Note that I got stuck trying to do pip install pycocoapi
normally on Windows.
(The following content is mainly troubleshooting + α at https://github.com/cocodataset/cocoapi/issues/51. [Other articles] at Qiita (https://qiita.com/kekekekenta/items/ca9d5d1f197c373656ec) ), But I added various things because the compiler flag was not enough and the build was moss.)
If git is not included in the first place, git for windows.
git clone https://github.com/cocodataset/cocoapi.git
So, I'm definitely moss trying to build.
cd cocoapi\PythonAPI
python setup.py build_ext install
#Various error messages below
So, from here on, troubleshoot according to the content of the error message.
ʻError: command'cl.exe' failed: If you get an error message like No such file or directory`, cl.exe is not in your PATH.
The easiest solution is to install Visual Studio and use ** Developer Command Prompt **. (Since there are various articles on how to install, see there.)
By the way, there are various types of developer command prompts, but this time I will use ** x64 Native Tools command prompt **.
To start it, install Visual Studio and type x64 Native
in the search bar.
Now, launch the x64 Native Tools command prompt for VS2017 and
cd cocoapi\PythonAPI #Path cloned cocoapi with git
python setup.py build_ext install
When I run, I get an error message like ʻinvalid numeric argument'/ Wno-cpp'`. (By the way, if you get an error that python does not exist before that, python's PATH is not in your path.)
So, empty ʻextra_compile_args around the 14th line of
cocoapi \ PythonAPI \ setup.py` as follows.
extra_compile_args=[],
#extra_compile_args=['-Wno-cpp', '-Wno-unused-function', '-std=c99'],
After rewriting, try again.
This time it is said that the header file is not enough, so rewrite ʻinclude_dirs in
cocoapi \ PythonAPI \ setup.py` as follows.
include_dirs = [np.get_include(), '../common', 'C:/Program Files (x86)/Windows Kits/10/Include/10.0.17763.0/ucrt', 'C:/Program Files (x86)/Windows Kits/10/Include/10.0.17763.0/winrt','C:/Program Files (x86)/Windows Kits/10/Include/10.0.17763.0/um','C:/Program Files (x86)/Windows Kits/10/Include/10.0.17763.0/shared'],
#include_dirs = [np.get_include(), '../common'],
-* 1: The part of 10.0.17763.0
differs depending on the version of Windows, so it is necessary to check the contents of C: \ Program Files (x86) \ Windows Kits \ 10 \ Include
with Explorer and rewrite it to the existing version. There is.
-* 2: If the contents of C: \ Program Files (x86) \ Windows Kits
do not exist, you need to add the Windows 10 SDK from the Visual Studio Installer.
Now that the linker flag is missing, ** add the following to the line following ʻinclude_dirs` **.
library_dirs = ['C:/Program Files (x86)/Windows Kits/10/Lib/10.0.17763.0/um/x64','C:/Program Files (x86)/Windows Kits/10/Lib/10.0.17763.0/ucrt/x64'],
10.0.17763.0
is the same as before. (If you're using the x86 command prompt instead of the x64 command prompt, you'll probably need to rewrite x64 to x86.)By the way, the final setup.py looks like this.
from setuptools import setup, Extension
import numpy as np
# To compile and install locally run "python setup.py build_ext --inplace"
# To install library to Python site-packages run "python setup.py build_ext install"
ext_modules = [
Extension(
'pycocotools._mask',
sources=['../common/maskApi.c', 'pycocotools/_mask.pyx'],
include_dirs = [np.get_include(), '../common', 'C:/Program Files (x86)/Windows Kits/10/Include/10.0.17763.0/ucrt', 'C:/Program Files (x86)/Windows Kits/10/Include/10.0.17763.0/winrt','C:/Program Files (x86)/Windows Kits/10/Include/10.0.17763.0/um','C:/Program Files (x86)/Windows Kits/10/Include/10.0.17763.0/shared'],
library_dirs = ['C:/Program Files (x86)/Windows Kits/10/Lib/10.0.17763.0/um/x64','C:/Program Files (x86)/Windows Kits/10/Lib/10.0.17763.0/ucrt/x64'],
extra_compile_args=[],
)
]
setup(
name='pycocotools',
packages=['pycocotools'],
package_dir = {'pycocotools': 'pycocotools'},
install_requires=[
'setuptools>=18.0',
'cython>=0.27.3',
'matplotlib>=2.1.0'
],
version='2.0',
ext_modules= ext_modules
)
This is the last fort. Add C: \ Program Files (x86) \ Windows Kits \ 10 \ bin \ x64
to your PATH, reopen the x64 Native Tools command prompt and run the same command.
(If you don't want to add this folder to your PATH, just copy the rc.exe
and rcdll.dll
inside and place them in a folder in your PATH.)
Ah, it was a long way. You can check if it is installed properly with the following command.
python
>>> from pycocotools.coco import COCO
>>>
OK if no error occurs.
Recommended Posts