问题:在Win10下Conda环境中通过pip install pycocotools出现如下错误提示:
Building wheel for pycocotools (setup.py) ... error
ERROR: Complete output from command 'D:\Anaconda3\envs\pytorch\python.exe' -u -c 'import setuptools, tokenize;__file__
='"'"'C:\\Users\\PC\\AppData\\Local\\Temp\\pip-install-pyq04a5d\\pycocotools\\setup.py'"'"';f=getattr(tokenize, '"'"'ope
n'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'
exec'"'"'))' bdist_wheel -d 'C:\Users\PC\AppData\Local\Temp\pip-wheel-m1nzlv6o' --python-tag cp36:
ERROR: running bdist_wheel
running build
running build_py
creating build
creating build\lib.win-amd64-3.6
creating build\lib.win-amd64-3.6\pycocotools
copying pycocotools\coco.py -> build\lib.win-amd64-3.6\pycocotools
copying pycocotools\cocoeval.py -> build\lib.win-amd64-3.6\pycocotools
copying pycocotools\mask.py -> build\lib.win-amd64-3.6\pycocotools
copying pycocotools\__init__.py -> build\lib.win-amd64-3.6\pycocotools
running build_ext
building 'pycocotools._mask' extension
creating build\temp.win-amd64-3.6
creating build\temp.win-amd64-3.6\Release
creating build\temp.win-amd64-3.6\Release\pycocotools
creating build\temp.win-amd64-3.6\Release\common
D:\vs2015\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -ID:\Anaconda3\envs\pytorch\lib\site-packages\nu
mpy\core\include -Icommon -ID:\Anaconda3\envs\pytorch\include -ID:\Anaconda3\envs\pytorch\include -ID:\vs2015\VC\INCLUDE
-ID:\vs2015\VC\ATLMFC\INCLUDE "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files
(x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\\shared" "-IC:\Program
Files (x86)\Windows Kits\8.1\include\\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\\winrt" /Tcpycocotools/_mas
k.c /Fobuild\temp.win-amd64-3.6\Release\pycocotools/_mask.obj -Wno-cpp -Wno-unused-function -std=c99
cl: 命令行 error D8021 :无效的数值参数“/Wno-cpp”
error: command 'D:\\vs2015\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2
----------------------------------------
ERROR: Failed building wheel for pycocotools
Running setup.py clean for pycocotools
Failed to build pycocotools
Installing collected packages: pycocotools
Running setup.py install for pycocotools ... error
ERROR: Complete output from command 'D:\Anaconda3\envs\pytorch\python.exe' -u -c 'import setuptools, tokenize;__file
__='"'"'C:\\Users\\PC\\AppData\\Local\\Temp\\pip-install-pyq04a5d\\pycocotools\\setup.py'"'"';f=getattr(tokenize, '"'"'o
pen'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'
"'exec'"'"'))' install --record 'C:\Users\PC\AppData\Local\Temp\pip-record-auc3rgky\install-record.txt' --single-version
-externally-managed --compile:
ERROR: running install
running build
running build_py
creating build
creating build\lib.win-amd64-3.6
creating build\lib.win-amd64-3.6\pycocotools
copying pycocotools\coco.py -> build\lib.win-amd64-3.6\pycocotools
copying pycocotools\cocoeval.py -> build\lib.win-amd64-3.6\pycocotools
copying pycocotools\mask.py -> build\lib.win-amd64-3.6\pycocotools
copying pycocotools\__init__.py -> build\lib.win-amd64-3.6\pycocotools
running build_ext
building 'pycocotools._mask' extension
creating build\temp.win-amd64-3.6
creating build\temp.win-amd64-3.6\Release
creating build\temp.win-amd64-3.6\Release\pycocotools
creating build\temp.win-amd64-3.6\Release\common
D:\vs2015\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -ID:\Anaconda3\envs\pytorch\lib\site-packages\
numpy\core\include -Icommon -ID:\Anaconda3\envs\pytorch\include -ID:\Anaconda3\envs\pytorch\include -ID:\vs2015\VC\INCLU
DE -ID:\vs2015\VC\ATLMFC\INCLUDE "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program File
s (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\\shared" "-IC:\Progra
m Files (x86)\Windows Kits\8.1\include\\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\\winrt" /Tcpycocotools/_m
ask.c /Fobuild\temp.win-amd64-3.6\Release\pycocotools/_mask.obj -Wno-cpp -Wno-unused-function -std=c99
cl: 命令行 error D8021 :无效的数值参数“/Wno-cpp”
error: command 'D:\\vs2015\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2
----------------------------------------
ERROR: Command "'D:\Anaconda3\envs\pytorch\python.exe' -u -c 'import setuptools, tokenize;__file__='"'"'C:\\Users\\PC\\A
ppData\\Local\\Temp\\pip-install-pyq04a5d\\pycocotools\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__
);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install -
-record 'C:\Users\PC\AppData\Local\Temp\pip-record-auc3rgky\install-record.txt' --single-version-externally-managed --co
mpile" failed with error code 1 in C:\Users\PC\AppData\Local\Temp\pip-install-pyq04a5d\pycocotools\
解决方法:
1. git clone https://github.com/cocodataset/cocoapi.git
2. cd cocoapi/PythonAPI
3. 删除setup.py中的红色框内的部分(如下图):
4. 执行:python setup.py build_ext inplace
5. 测试安装成功: python -m "import pycocotools"