cocodataset / cocoapi

COCO API - Dataset @ http://cocodataset.org/
Other
6.07k stars 3.75k forks source link

Got error while compiling PythonAPI #521

Open tarunmcom opened 3 years ago

tarunmcom commented 3 years ago

gcc -pthread -B /home/spc/anaconda3/envs/obj/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/spc/anaconda3/envs/obj/lib/python3.8/site-packages/numpy/core/include -I../common -I/home/spc/anaconda3/envs/obj/include/python3.8 -c pycocotools/_mask.c -o build/temp.linux-x86_64-3.8/pycocotools/_mask.o -Wno-cpp -Wno-unused-function -std=c99 gcc: error: pycocotools/_mask.c: No such file or directory error: command 'gcc' failed with exit status 1 Makefile:3: recipe for target 'all' failed make: *** [all] Error 1

joao-d-oliveira commented 3 years ago

Was also having problems with this, so noticed that the problem lies on the setup.py and MakeFile.

For me somehow the makefile was trying to compile using python2.7 instead of python3, so: at Makefile switched python ... to python3 ...(on both lines).

Then on setup.py was getting some errors, so took a look at the pull requests and noticed this Which basically changes: #extra_compile_args=['-Wno-cpp', '-Wno-unused-function', '-std=c99'], to extra_compile_args=['-std=c99'],.

worked for me


System: MacOS 11.4 (M1 chipset) Python: 3.8 gcc Apple clang version 12.0.5

RylanSchaeffer commented 2 years ago

I am getting what I think is the same error:

cocoapi/PythonAPI$ python setup.py build_ext install
running build_ext
building 'pycocotools._mask' extension
x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/rschaef/CoCoSci-Language-Distillation/CLIP_prefix_caption/clipgpt_venv/lib/python3.7/site-packages/numpy/core/include -I../common -I/home/rschaef/CoCoSci-Language-Distillation/CLIP_prefix_caption/clipgpt_venv/include -I/usr/include/python3.7m -c ../common/maskApi.c -o build/temp.linux-x86_64-3.7/../common/maskApi.o -std=c99
../common/maskApi.c: In function ‘rleToBbox’:
../common/maskApi.c:141:31: warning: ‘xp’ may be used uninitialized in this function [-Wmaybe-uninitialized]
       if(j%2==0) xp=x; else if(xp<x) { ys=0; ye=h-1; }
                               ^
x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/rschaef/CoCoSci-Language-Distillation/CLIP_prefix_caption/clipgpt_venv/lib/python3.7/site-packages/numpy/core/include -I../common -I/home/rschaef/CoCoSci-Language-Distillation/CLIP_prefix_caption/clipgpt_venv/include -I/usr/include/python3.7m -c pycocotools/_mask.c -o build/temp.linux-x86_64-3.7/pycocotools/_mask.o -std=c99
x86_64-linux-gnu-gcc: error: pycocotools/_mask.c: No such file or directory
x86_64-linux-gnu-gcc: fatal error: no input files
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

I tried @joao-d-oliveira 's suggestions:

1) Changed python to python3:

all:
    # install pycocotools locally
        python3 setup.py build_ext --inplace
        rm -rf build

install:
        # install pycocotools to the Python site-packages
        python3 setup.py build_ext install
        rm -rf build

2) Changed the extra_compile_args

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'],
        # extra_compile_args=['-Wno-cpp', '-Wno-unused-function', '-std=c99'],
        extra_compile_args=['-std=c99'],
    )
]

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
)  

No luck, still. Does anyone have any suggestions?

RylanSchaeffer commented 2 years ago

Ok, the trick is to install cython with pip install cython. See https://github.com/cocodataset/cocoapi/issues/141#issuecomment-386606299