ubuntu、anaconda虚拟环境中安装pycocotools

进入虚拟环境后
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

ubuntu、anaconda虚拟环境中安装pycocotools_第1张图片
解决办法:安装cython

pip install cython

在这里插入图片描述
然后在执行上面命令就不报错了
ubuntu、anaconda虚拟环境中安装pycocotools_第2张图片
4、安装build_ext

python setup.py build_ext install

然后不报错就成功了。
在这里插入图片描述

你可能感兴趣的:(笔记)