1. 程式人生 > >安裝pycocotools時報錯

安裝pycocotools時報錯

安裝pycocotools:

下載好安裝包到本地(連結:https://github.com/cocodataset/cocoapi),進入cocoapi-master/PythonAPI/資料夾下執行make編譯:

$ cd cocoapi-master/
$ cd PythonAPI/
$ make

報錯:

python setup.py build_ext --inplace
running build_ext
cythoning pycocotools/_mask.pyx to pycocotools/_mask.c
/home/dorothy/ZX/project/p1/venv1-p1/lib/python3.5/site-packages/Cython/Compiler/Main.py:367: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /home/dorothy/ZX/project/p1/venv1-p1/bin/cocoapi-master/PythonAPI/pycocotools/_mask.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)
building 'pycocotools._mask' extension
creating build
creating build/common
creating build/temp.linux-x86_64-3.5
creating build/temp.linux-x86_64-3.5/pycocotools
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/dorothy/ZX/project/p1/venv1-p1/lib/python3.5/site-packages/numpy/core/include -I../common -I/home/dorothy/ZX/project/p1/venv1-p1/include -I/usr/include/python3.5m -c ../common/maskApi.c -o build/temp.linux-x86_64-3.5/../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; }
                               ^
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/dorothy/ZX/project/p1/venv1-p1/lib/python3.5/site-packages/numpy/core/include -I../common -I/home/dorothy/ZX/project/p1/venv1-p1/include -I/usr/include/python3.5m -c pycocotools/_mask.c -o build/temp.linux-x86_64-3.5/pycocotools/_mask.o -Wno-cpp -Wno-unused-function -std=c99
pycocotools/_mask.c:4:20: fatal error: Python.h: 沒有那個檔案或目錄
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
Makefile:3: recipe for target 'all' failed
make: *** [all] Error 1

pycocotools/_mask.c:4:20: fatal error: Python.h: 沒有那個檔案或目錄

解決:(python3.5)

1. 安裝python3-dev

$ sudo apt-get install python3-dev 
正在讀取軟體包列表... 完成
正在分析軟體包的依賴關係樹       
正在讀取狀態資訊... 完成       
下列軟體包是自動安裝的並且現在不需要了:
  libcublas7.5 libcudart7.5 libcufft7.5 libcufftw7.5 libcurand7.5 libcusolver7.5 libcusparse7.5 libdrm-dev libgl1-mesa-dev libnppc7.5 libnppi7.5 libnpps7.5 libnvblas7.5 libnvrtc7.5 libnvtoolsext1
  libnvvm3 libpthread-stubs0-dev libthrust-dev libvdpau-dev libx11-dev libx11-doc libx11-xcb-dev libxau-dev libxcb-dri2-0-dev libxcb-dri3-dev libxcb-glx0-dev libxcb-present-dev libxcb-randr0-dev
  libxcb-render0-dev libxcb-shape0-dev libxcb-sync-dev libxcb-xfixes0-dev libxcb1-dev libxdamage-dev libxdmcp-dev libxext-dev libxfixes-dev libxshmfence-dev libxxf86vm-dev mesa-common-dev opencl-headers
  x11proto-core-dev x11proto-damage-dev x11proto-dri2-dev x11proto-fixes-dev x11proto-gl-dev x11proto-input-dev x11proto-kb-dev x11proto-xext-dev x11proto-xf86vidmode-dev xorg-sgml-doctools xtrans-dev
使用'sudo apt autoremove'來解除安裝它(它們)。
將會同時安裝下列軟體:
  libpython3-dev libpython3.5-dev python3.5-dev
下列【新】軟體包將被安裝:
  libpython3-dev libpython3.5-dev python3-dev python3.5-dev
升級了 0 個軟體包,新安裝了 4 個軟體包,要解除安裝 0 個軟體包,有 176 個軟體包未被升級。
需要下載 37.7 MB 的歸檔。
解壓縮後會消耗 54.0 MB 的額外空間。
您希望繼續執行嗎? [Y/n] y
獲取:1 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main amd64 libpython3.5-dev amd64 3.5.2-2ubuntu0~16.04.5 [37.3 MB]
獲取:2 http://cn.archive.ubuntu.com/ubuntu xenial/main amd64 libpython3-dev amd64 3.5.1-3 [6,926 B]                                                                                                        
獲取:3 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main amd64 python3.5-dev amd64 3.5.2-2ubuntu0~16.04.5 [413 kB]                                                                                   
獲取:4 http://cn.archive.ubuntu.com/ubuntu xenial/main amd64 python3-dev amd64 3.5.1-3 [1,186 B]                                                                                                           
已下載 37.7 MB,耗時 2分 54秒 (216 kB/s)                                                                                                                                                                   
正在選中未選擇的軟體包 libpython3.5-dev:amd64。
(正在讀取資料庫 ... 系統當前共安裝有 256230 個檔案和目錄。)
正準備解包 .../libpython3.5-dev_3.5.2-2ubuntu0~16.04.5_amd64.deb  ...
正在解包 libpython3.5-dev:amd64 (3.5.2-2ubuntu0~16.04.5) ...
正在選中未選擇的軟體包 libpython3-dev:amd64。
正準備解包 .../libpython3-dev_3.5.1-3_amd64.deb  ...
正在解包 libpython3-dev:amd64 (3.5.1-3) ...
正在選中未選擇的軟體包 python3.5-dev。
正準備解包 .../python3.5-dev_3.5.2-2ubuntu0~16.04.5_amd64.deb  ...
正在解包 python3.5-dev (3.5.2-2ubuntu0~16.04.5) ...
正在選中未選擇的軟體包 python3-dev。
正準備解包 .../python3-dev_3.5.1-3_amd64.deb  ...
正在解包 python3-dev (3.5.1-3) ...
正在處理用於 man-db (2.7.5-1) 的觸發器 ...
正在設定 libpython3.5-dev:amd64 (3.5.2-2ubuntu0~16.04.5) ...
正在設定 libpython3-dev:amd64 (3.5.1-3) ...
正在設定 python3.5-dev (3.5.2-2ubuntu0~16.04.5) ...
正在設定 python3-dev (3.5.1-3) ...

2. 編譯

$ make
python3 setup.py build_ext --inplace
running build_ext
skipping 'pycocotools/_mask.c' Cython extension (up-to-date)
building 'pycocotools._mask' extension
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/dorothy/ZX/project/p1/venv1-p1/lib/python3.5/site-packages/numpy/core/include -I../common -I/home/dorothy/ZX/project/p1/venv1-p1/include -I/usr/include/python3.5m -c ../common/maskApi.c -o build/temp.linux-x86_64-3.5/../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; }
                               ^
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/dorothy/ZX/project/p1/venv1-p1/lib/python3.5/site-packages/numpy/core/include -I../common -I/home/dorothy/ZX/project/p1/venv1-p1/include -I/usr/include/python3.5m -c pycocotools/_mask.c -o build/temp.linux-x86_64-3.5/pycocotools/_mask.o -Wno-cpp -Wno-unused-function -std=c99
creating build/lib.linux-x86_64-3.5
creating build/lib.linux-x86_64-3.5/pycocotools
x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.5/../common/maskApi.o build/temp.linux-x86_64-3.5/pycocotools/_mask.o -o build/lib.linux-x86_64-3.5/pycocotools/_mask.cpython-35m-x86_64-linux-gnu.so
copying build/lib.linux-x86_64-3.5/pycocotools/_mask.cpython-35m-x86_64-linux-gnu.so -> pycocotools
rm -rf build