install pycocotools in Mac m1

1k views Asked by At

python 3.9 pip 22.3.1 setuptools 66.0.0 wheel 0.38.4

when install yolox, there is always error in installing pycocotools as below:

× Building wheel for pycocotools (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [33 lines of output] running bdist_wheel running build running build_py creating build creating build/lib.macosx-10.9-universal2-cpython-39 creating build/lib.macosx-10.9-universal2-cpython-39/pycocotools copying pycocotools/coco.py -> build/lib.macosx-10.9-universal2-cpython-39/pycocotools copying pycocotools/mask.py -> build/lib.macosx-10.9-universal2-cpython-39/pycocotools copying pycocotools/init.py -> build/lib.macosx-10.9-universal2-cpython-39/pycocotools copying pycocotools/cocoeval.py -> build/lib.macosx-10.9-universal2-cpython-39/pycocotools running build_ext cythoning pycocotools/_mask.pyx to pycocotools/mask.c /private/var/folders/g9/4g2rq3px69lbr64qqpmw5_280000gn/T/pip-build-env-kb70uki/overlay/lib/python3.9/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /private/var/folders/g9/4g2rq3px69lbr64qqpmw5_280000gn/T/pip-install-zc58cnkb/pycocotools_f63b404805f6427bb06acdd61bfd63a0/pycocotools/mask.pyx tree = Parsing.p_module(s, pxd, full_module_name) building 'pycocotools.mask' extension creating build/temp.macosx-10.9-universal2-cpython-39 creating build/temp.macosx-10.9-universal2-cpython-39/common creating build/temp.macosx-10.9-universal2-cpython-39/pycocotools clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -iwithsysroot/System/Library/Frameworks/System.framework/PrivateHeaders -iwithsysroot/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/Headers -arch arm64 -arch x86_64 -Werror=implicit-function-declaration -I/private/var/folders/g9/4g2rq3px69lbr64qqpmw5_280000gn/T/pip-build-env-kb70uki/overlay/lib/python3.9/site-packages/numpy/core/include -I./common -I/Users/zhangelaine/env/YOLOX/include -I/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/Headers -c ./common/maskApi.c -o build/temp.macosx-10.9-universal2-cpython-39/./common/maskApi.o -Wno-cpp -Wno-unused-function -std=c99 ./common/maskApi.c:151:32: warning: unused variable 'xp' [-Wunused-variable] uint h, w, xs, ys, xe, ye, xp, cc; siz j, m; ^ 1 warning generated. ./common/maskApi.c:151:32: warning: unused variable 'xp' [-Wunused-variable] uint h, w, xs, ys, xe, ye, xp, cc; siz j, m; ^ 1 warning generated. clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -iwithsysroot/System/Library/Frameworks/System.framework/PrivateHeaders -iwithsysroot/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/Headers -arch arm64 -arch x86_64 -Werror=implicit-function-declaration -I/private/var/folders/g9/4g2rq3px69lbr64qqpmw5_280000gn/T/pip-build-env-kb70uki/overlay/lib/python3.9/site-packages/numpy/core/include -I./common -I/Users/zhangelaine/env/YOLOX/include -I/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/Headers -c pycocotools/_mask.c -o build/temp.macosx-10.9-universal2-cpython-39/pycocotools/_mask.o -Wno-cpp -Wno-unused-function -std=c99 pycocotools/_mask.c:6:10: fatal error: 'Python.h' file not found #include "Python.h" ^~~~~~~~~~ 1 error generated. error: command '/usr/bin/clang' failed with exit code 1 [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for pycocotools Failed to build pycocotools ERROR: Could not build wheels for pycocotools, which is required to install pyproject.toml-based projects

so i goto pycocotools website to downlord whl file. https://pypi.tuna.tsinghua.edu.cn/simple/pycocotools-windows/ and got error as below

ERROR: pycocotools_windows-2.0.0.2-cp37-cp37m-win_amd64.whl is not a supported wheel on this platform.

any suggestion ? thanks a lot

2

There are 2 answers

0
Patrick On

solution : use miniforge to install conda

and install pycocotools with conda in Mac m1. It works, no error anymore

however pip install in conda env is a little bit complicated,

i am tring it.

0
imabelle On

That hint from pioneer78 was perfect.

I combined that with a reference I found elsewhere and now I have the latest pycocotools running on my M1:

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

FYI: this also fixed an issue I was having with detectron2 cocoevaluator where I was getting a type error (can't convert float64 to int). I suspected it was because detectron2 wanted pycocotools 2.0.2 and I had only found a way to get 2.0 installed until now.