如果直接用pip install pycocotools,会出现错误提示:

(tf14) C:\Users\ljm\AppData\Local\Continuum\anaconda3\envs\tf14>pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
Collecting git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
  Cloning https://github.com/philferriere/cocoapi.git to c:\users\ljm\appdata\local\temp\pip-req-build-mchdbk0j
  Running command git clone -q https://github.com/philferriere/cocoapi.git 'C:\Users\ljm\AppData\Local\Temp\pip-req-build-mchdbk0j'
Building wheels for collected packages: pycocotools
  Building wheel for pycocotools (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'C:\Users\ljm\AppData\Local\Continuum\anaconda3\envs\tf14\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\ljm\\AppData\\Local\\Temp\\pip-req-build-mchdbk0j\\PythonAPI\\setup.py'"'"'; __file__='"'"'C:\\Users\\ljm\\AppData\\Local\\Temp\\pip-req-build-mchdbk0j\\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 'C:\Users\ljm\AppData\Local\Temp\pip-wheel-v1lwyj9m' --python-tag cp37
       cwd: C:\Users\ljm\AppData\Local\Temp\pip-req-build-mchdbk0j\PythonAPI
  Complete output (28 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win-amd64-3.7
  creating build\lib.win-amd64-3.7\pycocotools
  copying pycocotools\coco.py -> build\lib.win-amd64-3.7\pycocotools
  copying pycocotools\cocoeval.py -> build\lib.win-amd64-3.7\pycocotools
  copying pycocotools\mask.py -> build\lib.win-amd64-3.7\pycocotools
  copying pycocotools\__init__.py -> build\lib.win-amd64-3.7\pycocotools
  running build_ext
  building 'pycocotools._mask' extension
  creating build\temp.win-amd64-3.7
  creating build\temp.win-amd64-3.7\Release
  creating build\temp.win-amd64-3.7\Release\pycocotools
  creating build\temp.win-amd64-3.7\common
  C:\Program Files (x86)\Microsoft Visual Studio\2017\WDExpress\VC\Tools\MSVC\14.14.26428\bin\Hostx86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\ljm\AppData\Local\Continuum\anaconda3\envs\tf14\lib\site-packages\numpy\core\include -I../common -IC:\Users\ljm\AppData\Local\Continuum\anaconda3\envs\tf14\include -IC:\Users\ljm\AppData\Local\Continuum\anaconda3\envs\tf14\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\WDExpress\VC\Tools\MSVC\14.14.26428\Include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.2\include\um" /Tcpycocotools/_mask.c /Fobuild\temp.win-amd64-3.7\Release\pycocotools/_mask.obj
  _mask.c
  c1: fatal error C1356: unable to find mspdbcore.dll
  error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\WDExpress\\VC\\Tools\\MSVC\\14.14.26428\\bin\\Hostx86\\x64\\cl.exe' failed with exit status 2
  ----------------------------------------
  ERROR: Failed building wheel for pycocotools
  Running setup.py clean for pycocotools
  ERROR: Command errored out with exit status 1:
   command: 'C:\Users\ljm\AppData\Local\Continuum\anaconda3\envs\tf14\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\ljm\\AppData\\Local\\Temp\\pip-req-build-mchdbk0j\\PythonAPI\\setup.py'"'"'; __file__='"'"'C:\\Users\\ljm\\AppData\\Local\\Temp\\pip-req-build-mchdbk0j\\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: C:\Users\ljm\AppData\Local\Temp\pip-req-build-mchdbk0j
  Complete output (13 lines):
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\ljm\AppData\Local\Temp\pip-req-build-mchdbk0j\PythonAPI\setup.py", line 25, in <module>
      cythonize(ext_modules)
    File "C:\Users\ljm\AppData\Local\Continuum\anaconda3\envs\tf14\lib\site-packages\Cython\Build\Dependencies.py", line 966, in cythonize
      aliases=aliases)
    File "C:\Users\ljm\AppData\Local\Continuum\anaconda3\envs\tf14\lib\site-packages\Cython\Build\Dependencies.py", line 810, in create_extension_list
      for file in nonempty(sorted(extended_iglob(filepattern)), "'%s' doesn't match any files" % filepattern):
    File "C:\Users\ljm\AppData\Local\Continuum\anaconda3\envs\tf14\lib\site-packages\Cython\Build\Dependencies.py", line 109, 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: 'C:\Users\ljm\AppData\Local\Continuum\anaconda3\envs\tf14\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\ljm\\AppData\\Local\\Temp\\pip-req-build-mchdbk0j\\PythonAPI\\setup.py'"'"'; __file__='"'"'C:\\Users\\ljm\\AppData\\Local\\Temp\\pip-req-build-mchdbk0j\\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 'C:\Users\ljm\AppData\Local\Temp\pip-record-t6mahjah\install-record.txt' --single-version-externally-managed --compile
         cwd: C:\Users\ljm\AppData\Local\Temp\pip-req-build-mchdbk0j\PythonAPI
    Complete output (17 lines):
    running install
    running build
    running build_py
    running build_ext
    building 'pycocotools._mask' extension
    C:\Program Files (x86)\Microsoft Visual Studio\2017\WDExpress\VC\Tools\MSVC\14.14.26428\bin\Hostx86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\ljm\AppData\Local\Continuum\anaconda3\envs\tf14\lib\site-packages\numpy\core\include -I../common -IC:\Users\ljm\AppData\Local\Continuum\anaconda3\envs\tf14\include -IC:\Users\ljm\AppData\Local\Continuum\anaconda3\envs\tf14\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\WDExpress\VC\Tools\MSVC\14.14.26428\Include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.2\include\um" /Tcpycocotools/_mask.c /Fobuild\temp.win-amd64-3.7\Release\pycocotools/_mask.obj
    _mask.c
    c1: fatal error C1356: unable to find mspdbcore.dll
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\WDExpress\\VC\\Tools\\MSVC\\14.14.26428\\bin\\Hostx86\\x64\\cl.exe' failed with exit status 2
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'C:\Users\ljm\AppData\Local\Continuum\anaconda3\envs\tf14\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\ljm\\AppData\\Local\\Temp\\pip-req-build-mchdbk0j\\PythonAPI\\setup.py'"'"'; __file__='"'"'C:\\Users\\ljm\\AppData\\Local\\Temp\\pip-req-build-mchdbk0j\\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 'C:\Users\ljm\AppData\Local\Temp\pip-record-t6mahjah\install-record.txt' --single-version-externally-managed --compile Check the logs for full command output.

解决办法参考资料:

https://github.com/cocodataset/cocoapi/issues/169

https://www.jianshu.com/p/8658cda3d553

我的开发环境是Windows10+Anaconda,创建的环境叫做tf14,所以我首先在anaconda的cmd窗口激活tf14,再转到tf14的环境目录,先放在这

(base) C:\>activate tf14

(tf14) C:\>cd C:\Users\ljm\AppData\Local\Continuum\anaconda3\envs\tf14

下载Windows下的pycocotools, 链接: https://github.com/philferriere/cocoapi

下载后,解压到文件夹C:\Users\ljm\AppData\Local\Continuum\anaconda3\envs\tf14\cocoapi,并执行:

# install pycocotools locally
C:\Users\ljm\AppData\Local\Continuum\anaconda3\envs\tf14\cocoapi\PythonAPI>python setup.py build_ext --inplace
 
# install pycocotools to the Python site-packages
C:\Users\ljm\AppData\Local\Continuum\anaconda3\envs\tf14\cocoapi\PythonAPI>python setup.py build_ext install

如果出现错误编译错误,需要安装Microsoft Visual C++ Build Tools, 链接:https://go.microsoft.com/fwlink/?LinkId=691126

 

 

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐