安装pycocotools烦死了
方法指路评论区
原文保留用于问题搜索
/root/anaconda3/envs/tensorflow/compiler_compat/ld: /usr/local/cuda-9.0/lib64: file not recognized: Is a directory
collect2: error: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
这个问题真的好讨厌
记录一下
----------------------
ubuntu 16.04
----------------------
先创建一个conda环境
# conda create -n pycocotools_env python=3.7
进入环境
# source activate pycocotools_env
查看一下gcc的版本,4.9.4
# gcc --version
gcc (Ubuntu 4.9.4-2ubuntu1~16.04) 4.9.4
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
如果要更换gcc版本参考,还是非常方便的 Ubuntu14下gcc4.8和gcc4.7之间的切换_d5224的专栏-CSDN博客
----------------------
最容易搜到的方法
# pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
有几个依赖的问题
ModuleNotFoundError: No module named 'Cython'
ModuleNotFoundError: No module named 'numpy'
都安装一下
# pip install Cython
# pip install numpy
再次运行出现一堆问题
Building wheel for pycocotools (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /root/anaconda3/envs/pycocotools/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-txkliuq9/PythonAPI/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-txkliuq9/PythonAPI/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-rb1gl52y
cwd: /tmp/pip-req-build-txkliuq9/PythonAPI
Complete output (34 lines):
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.7
creating build/lib.linux-x86_64-3.7/pycocotools
copying pycocotools/__init__.py -> build/lib.linux-x86_64-3.7/pycocotools
copying pycocotools/coco.py -> build/lib.linux-x86_64-3.7/pycocotools
copying pycocotools/mask.py -> build/lib.linux-x86_64-3.7/pycocotools
copying pycocotools/cocoeval.py -> build/lib.linux-x86_64-3.7/pycocotools
running build_ext
building 'pycocotools._mask' extension
creating build/temp.linux-x86_64-3.7
creating build/temp.linux-x86_64-3.7/pycocotools
creating build/common
gcc -pthread -B /root/anaconda3/envs/pycocotools/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes /usr/local/cuda-9.0/include -fPIC -I/root/anaconda3/envs/pycocotools/lib/python3.7/site-packages/numpy/core/include -I../common -I/root/anaconda3/envs/pycocotools/include/python3.7m -c pycocotools/_mask.c -o build/temp.linux-x86_64-3.7/pycocotools/_mask.o
In file included from /root/anaconda3/envs/pycocotools/lib/python3.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1944:0,
from /root/anaconda3/envs/pycocotools/lib/python3.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
from /root/anaconda3/envs/pycocotools/lib/python3.7/site-packages/numpy/core/include/numpy/arrayobject.h:4,
from pycocotools/_mask.c:636:
/root/anaconda3/envs/pycocotools/lib/python3.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
#warning "Using deprecated NumPy API, disable it with " \
gcc: warning: /usr/local/cuda-9.0/include: linker input file unused because linking not done
gcc -pthread -B /root/anaconda3/envs/pycocotools/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes /usr/local/cuda-9.0/include -fPIC -I/root/anaconda3/envs/pycocotools/lib/python3.7/site-packages/numpy/core/include -I../common -I/root/anaconda3/envs/pycocotools/include/python3.7m -c ../common/maskApi.c -o build/temp.linux-x86_64-3.7/../common/maskApi.o
../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: warning: /usr/local/cuda-9.0/include: linker input file unused because linking not done
gcc -pthread -shared -B /root/anaconda3/envs/pycocotools/compiler_compat -L/root/anaconda3/envs/pycocotools/lib -Wl,-rpath=/root/anaconda3/envs/pycocotools/lib -Wl,--no-as-needed -Wl,--sysroot=/ /usr/local/cuda-9.0/lib64 /usr/local/cuda-9.0/include build/temp.linux-x86_64-3.7/pycocotools/_mask.o build/temp.linux-x86_64-3.7/../common/maskApi.o -o build/lib.linux-x86_64-3.7/pycocotools/_mask.cpython-37m-x86_64-linux-gnu.so
/root/anaconda3/envs/pycocotools/compiler_compat/ld: /usr/local/cuda-9.0/lib64: file not recognized: Is a directory
collect2: error: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for pycocotools
Running setup.py clean for pycocotools
ERROR: Command errored out with exit status 1:
command: /root/anaconda3/envs/pycocotools/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-txkliuq9/PythonAPI/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-txkliuq9/PythonAPI/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' clean --all
cwd: /tmp/pip-req-build-txkliuq9
Complete output (11 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-req-build-txkliuq9/PythonAPI/setup.py", line 25, in <module>
cythonize(ext_modules)
File "/root/anaconda3/envs/pycocotools/lib/python3.7/site-packages/Cython/Build/Dependencies.py", line 972, in cythonize
aliases=aliases)
File "/root/anaconda3/envs/pycocotools/lib/python3.7/site-packages/Cython/Build/Dependencies.py", line 815, in create_extension_list
for file in nonempty(sorted(extended_iglob(filepattern)), "'%s' doesn't match any files" % filepattern):
File "/root/anaconda3/envs/pycocotools/lib/python3.7/site-packages/Cython/Build/Dependencies.py", line 114, in nonempty
raise ValueError(error_msg)
ValueError: 'pycocotools/_mask.pyx' doesn't match any files
----------------------------------------
ERROR: Failed cleaning build dir for pycocotools
Failed to build pycocotools
Installing collected packages: pycocotools
Running setup.py install for pycocotools ... error
ERROR: Command errored out with exit status 1:
command: /root/anaconda3/envs/pycocotools/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-txkliuq9/PythonAPI/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-txkliuq9/PythonAPI/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-hamgsy2_/install-record.txt --single-version-externally-managed --compile --install-headers /root/anaconda3/envs/pycocotools/include/python3.7m/pycocotools
cwd: /tmp/pip-req-build-txkliuq9/PythonAPI
Complete output (24 lines):
running install
running build
running build_py
running build_ext
building 'pycocotools._mask' extension
gcc -pthread -B /root/anaconda3/envs/pycocotools/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes /usr/local/cuda-9.0/include -fPIC -I/root/anaconda3/envs/pycocotools/lib/python3.7/site-packages/numpy/core/include -I../common -I/root/anaconda3/envs/pycocotools/include/python3.7m -c pycocotools/_mask.c -o build/temp.linux-x86_64-3.7/pycocotools/_mask.o
In file included from /root/anaconda3/envs/pycocotools/lib/python3.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1944:0,
from /root/anaconda3/envs/pycocotools/lib/python3.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
from /root/anaconda3/envs/pycocotools/lib/python3.7/site-packages/numpy/core/include/numpy/arrayobject.h:4,
from pycocotools/_mask.c:636:
/root/anaconda3/envs/pycocotools/lib/python3.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
#warning "Using deprecated NumPy API, disable it with " \
gcc: warning: /usr/local/cuda-9.0/include: linker input file unused because linking not done
gcc -pthread -B /root/anaconda3/envs/pycocotools/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes /usr/local/cuda-9.0/include -fPIC -I/root/anaconda3/envs/pycocotools/lib/python3.7/site-packages/numpy/core/include -I../common -I/root/anaconda3/envs/pycocotools/include/python3.7m -c ../common/maskApi.c -o build/temp.linux-x86_64-3.7/../common/maskApi.o
../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: warning: /usr/local/cuda-9.0/include: linker input file unused because linking not done
gcc -pthread -shared -B /root/anaconda3/envs/pycocotools/compiler_compat -L/root/anaconda3/envs/pycocotools/lib -Wl,-rpath=/root/anaconda3/envs/pycocotools/lib -Wl,--no-as-needed -Wl,--sysroot=/ /usr/local/cuda-9.0/lib64 /usr/local/cuda-9.0/include build/temp.linux-x86_64-3.7/pycocotools/_mask.o build/temp.linux-x86_64-3.7/../common/maskApi.o -o build/lib.linux-x86_64-3.7/pycocotools/_mask.cpython-37m-x86_64-linux-gnu.so
/root/anaconda3/envs/pycocotools/compiler_compat/ld: /usr/local/cuda-9.0/lib64: file not recognized: Is a directory
collect2: error: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /root/anaconda3/envs/pycocotools/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-txkliuq9/PythonAPI/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-txkliuq9/PythonAPI/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-hamgsy2_/install-record.txt --single-version-externally-managed --compile --install-headers /root/anaconda3/envs/pycocotools/include/python3.7m/pycocotools Check the logs for full command output.
挑点看得懂的
Building wheels for collected packages: pycocotools
Building wheel for pycocotools (setup.py) ... error
/root/anaconda3/envs/pycocotools/compiler_compat/ld: /usr/local/cuda-9.0/lib64: file not recognized: Is a directory
collect2: error: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
Running setup.py clean for pycocotools
ValueError: 'pycocotools/_mask.pyx' doesn't match any files
Installing collected packages: pycocotools
Running setup.py install for pycocotools ... error
/root/anaconda3/envs/pycocotools/compiler_compat/ld: /usr/local/cuda-9.0/lib64: file not recognized: Is a directory
collect2: error: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /root/anaconda3/envs/pycocotools/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-txkliuq9/PythonAPI/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-txkliuq9/PythonAPI/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-hamgsy2_/install-record.txt --single-version-externally-managed --compile --install-headers /root/anaconda3/envs/pycocotools/include/python3.7m/pycocotools Check the logs for full command output.
搜一下
ValueError: 'pycocotools/_mask.pyx' doesn't match any files
官方解释
If you get this error, it is because the COCO library you are calling is NOT our version of the library. Instead, you are (inadvertently) referencing a local copy of the library. So, if you get this error, search the tree of import in your code for a reference to a local pycocotools library. Then, move or delete the local version.
我本地可不止一个pycocotools,哭了,万一我都删掉了又没安装成功这个pycocotools怎么办,傻眼
搜到另外一个人的说法
@leekyungmoon @asylbek27 Please see here "https://github.com/philferriere/cocoapi". To summarize, after download api, then run pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI.
先下载source
# git clone --recursive https://github.com/philferriere/cocoapi.git
再运行
# pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPIls
error确实缩减了不少,只剩下
ERROR: Error [Errno 2] No such file or directory: '/tmp/pip-req-build-hcfx4gv4/PythonAPIls': '/tmp/pip-req-build-hcfx4gv4/PythonAPIls' while executing command python setup.py egg_info
ERROR: Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: '/tmp/pip-req-build-hcfx4gv4/PythonAPIls': '/tmp/pip-req-build-hcfx4gv4/PythonAPIls'
看到这样一个说法 pip安裝軟體時出現Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build*的解決方案
于是我按照他说的
# python -m pip install --upgrade --force pip
# pip install setuptools==33.1.1
于是错误变成了
ERROR: Error [Errno 2] No such file or directory: '/tmp/pip-req-build-mhmyk16y/PythonAPIls': '/tmp/pip-req-build-mhmyk16y/PythonAPIls' while executing command python setup.py egg_info
ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: '/tmp/pip-req-build-mhmyk16y/PythonAPIls': '/tmp/pip-req-build-mhmyk16y/PythonAPIls'
→_→
看了一下 no module named _mask? · Issue #59 · cocodataset/cocoapi
怎么好像都在说windows→_→
换个source cocodataset/cocoapi
# cd cocoapi/PythonAPI
# make
得到错误
/root/anaconda3/envs/pycocotools/compiler_compat/ld: /usr/local/cuda-9.0/lib64: file not recognized: Is a directory
collect2: error: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
Makefile:3: recipe for target 'all' failed
make: *** [all] Error 1
换个方式
# python PythonAPI/setup.py build_ext install
得到错误
running build_ext
cythoning pycocotools/_mask.pyx to pycocotools/_mask.c
error: /your/onw/path/cocoapi/pycocotools/_mask.pyxno module named _mask? · Issue #59 · cocodataset/cocoapirunning build_ext
cythoning pycocotools/_mask.pyx to pycocotools/_mask.c
error: /your/onw/path/cocoapi/pycocotools/_mask.pyx
no module named _mask? · Issue #59 · cocodataset/cocoapi
进入到PythonAPI文件夹里
# python setup.py build_ext install
得到错误
/root/anaconda3/envs/pycocotools/compiler_compat/ld: /usr/local/cuda-9.0/lib64: file not recognized: Is a directory
collect2: error: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
参考 pycocotools安装失败 compiler_compat/ld
修改ld名字
再次运行
得到错误
/usr/bin/ld: cannot find /usr/local/cuda-9.0/lib64: File format not recognized
/usr/bin/ld: cannot find /usr/local/cuda-9.0/include: File format not recognized