进入虚拟环境后
1、获取源码
git clone https://github.com/pdollar/coco.git
2、编译
cd coco/PythonAPI
3、本地安装
# install pycocotools locally
python setup.py build_ext --inplace
然后报错了
running build_ext
building 'pycocotools._mask' extension
creating build
creating build/common
creating build/temp.linux-x86_64-3.7
creating build/temp.linux-x86_64-3.7/pycocotools
gcc -pthread -B /home/sys507/anaconda3/envs/pytorch/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/sys507/anaconda3/envs/pytorch/lib/python3.7/site-packages/numpy/core/include -I../common -I/home/sys507/anaconda3/envs/pytorch/include/python3.7m -c ../common/maskApi.c -o build/temp.linux-x86_64-3.7/../common/maskApi.o -Wno-cpp -Wno-unused-function -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; }
^
gcc -pthread -B /home/sys507/anaconda3/envs/pytorch/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/sys507/anaconda3/envs/pytorch/lib/python3.7/site-packages/numpy/core/include -I../common -I/home/sys507/anaconda3/envs/pytorch/include/python3.7m -c pycocotools/_mask.c -o build/temp.linux-x86_64-3.7/pycocotools/_mask.o -Wno-cpp -Wno-unused-function -std=c99
gcc: error: pycocotools/_mask.c: 没有那个文件或目录
error: command 'gcc' failed with exit status 1
解决办法:安装cython
pip install cython
然后在执行上面命令就不报错了
4、安装build_ext
python setup.py build_ext install
然后不报错就成功了。
来源:CSDN
作者:奔跑的小仙女
链接:https://blog.csdn.net/qq_43211132/article/details/103599329