无法在Windows中安装pycocotools:致命错误C1083:无法打开包含文件:io.h:无此类文件或目录错误:

时间:2018-10-21 21:50:34

标签: python windows tensorflow object-detection object-detection-api

我是机器学习的新手,从拥有GeForce GTX 540M的Windows 8.1 PC开始。我遵循此tutorial来开始物体检测模型。我建立了自己的数据集,并尝试按照教程进行训练,但使用的是“ ssd_mobilenet_v1_coco_2017_11_17”模型。但是由于我对本教程中给出的“ train.py”文件有麻烦,因此无法成功执行。

因此,我搜索了一下,发现我们必须使用“ model_main.py”来训练模型。尝试使用“ model_main.py”进行训练时,出现此错误:
"ImportModuleError: No module named 'pycocotools' was found"

因此,我尝试从此link安装cocoapi。我按照给出的说明进行操作,但是遇到了如下所示的错误,我尝试了很多解决方案,但没有任何效果。任何帮助将不胜感激。

(tensorflow1) C:\tensorflow1\models\research\object_detection>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\home\appdata\l
ocal\temp\pip-req-build-76t4e6ys
Building wheels for collected packages: pycocotools
  Running setup.py bdist_wheel for pycocotools ... error
  Complete output from command c:\users\home\anaconda3\envs\tensorflow1\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Home\\AppData\\Local\\Temp\\pip-req-build-76t4e6ys\\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\Home\AppData\Local\Temp\pip-wheel-4_r37hm6 --python-tag cp36:
  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\common
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\bin\HostX86\x64\cl.exe /c/nologo /Ox /W3 /GL /DNDEBUG /MD -Ic:\users\home\anaconda3\envs\tensorflow1\lib\site-packages\numpy\core\include -I../common -Ic:\users\home\anaconda3\envs\tensorflow1\include -Ic:\users\home\anaconda3\envs\tensorflow1\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\include" /Tcpycocotools/_mask.c /Fobuild\temp.win-amd64-3.6\Release\pycocotools/_mask.obj
  _mask.c
  c:\users\home\anaconda3\envs\tensorflow1\include\pyconfig.h(59): fatal error C1083: Cannot open include file: 'io.h': No such file or directory
  error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.15.26726\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2

  ----------------------------------------
  Failed building wheel for pycocotools
  Running setup.py clean for pycocotools
  Complete output from command c:\users\home\anaconda3\envs\tensorflow1\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Home\\AppData\\Local\\Temp\\pip-req-build-76t4e6ys\\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:
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\Home\AppData\Local\Temp\pip-req-build-76t4e6ys\PythonAPI\setup.py", line 25, in <module>
      cythonize(ext_modules)
    File "c:\users\home\anaconda3\envs\tensorflow1\lib\site-packages\Cython\Build\Dependencies.py", line 956, in cythonize
      aliases=aliases)
    File "c:\users\home\anaconda3\envs\tensorflow1\lib\site-packages\Cython\Buil
d\Dependencies.py", line 801, in create_extension_list
      for file in nonempty(sorted(extended_iglob(filepattern)), "'%s' doesn't ma
tch any files" % filepattern):
    File "c:\users\home\anaconda3\envs\tensorflow1\lib\site-packages\Cython\Buil
d\Dependencies.py", line 111, in nonempty
      raise ValueError(error_msg)
  ValueError: 'pycocotools/_mask.pyx' doesn't match any files

  ----------------------------------------
  Failed cleaning build dir for pycocotools
Failed to build pycocotools
Installing collected packages: pycocotools
  Running setup.py install for pycocotools ... error
    Complete output from command c:\users\home\anaconda3\envs\tensorflow1\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Home\\AppData\\Local\\Temp\\pip-req-build-76t4e6ys\\PythonAPI\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" build_ext "-L/C:/Program Files (x86)/Windows Kits/10/Include/10.0.17134.0/ucrt" install --record C:\Users\Home\AppData\Local\Temp\pip-record-ykypadav\install-record.txt --single-version-externally-managed --compile:
    running build_ext
    building 'pycocotools._mask' extension
    C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\bin\HostX86\x64\cl.exe /c/nologo /Ox /W3 /GL /DNDEBUG /MD -Ic:\users\home\anaconda3\envs\tensorflow1\lib\site-packages\numpy\core\include -I../common -Ic:\users\home\anaconda3\envs\tensorflow1\include -Ic:\users\home\anaconda3\envs\tensorflow1\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\include" /Tcpycocotools/_mask.c /Fobuild\temp.win-amd64-3.6\Release\pycocotools/_mask.obj
    _mask.c
    c:\users\home\anaconda3\envs\tensorflow1\include\pyconfig.h(59): fatal error
 C1083: Cannot open include file: 'io.h': No such file or directory
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.15.26726\\bin\\HostX86\\x64\\cl.exe' failed with exit
 status 2

    ----------------------------------------
Command "c:\users\home\anaconda3\envs\tensorflow1\python.exe -u -c "import setup
tools, tokenize;__file__='C:\\Users\\Home\\AppData\\Local\\Temp\\pip-req-build-76t4e6ys\\PythonAPI\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" build_ext "-L/C:/Program Files (x86)/Windows Kits/10/Include/10.0.17134.0/ucrt" install --record C:\Users\Home\AppData\Local\Temp\pip-record-ykypadav\install-record.txt --single-version-externally-managed --compile" failed with error code 1
in C:\Users\Home\AppData\Local\Temp\pip-req-build-76t4e6ys\PythonAPI

(tensorflow1) C:\tensorflow1\models\research\object_detection>

7 个答案:

答案 0 :(得分:2)

轻松修复,请使用pip install pycocotools-windows

答案 1 :(得分:1)

我遇到了同样的错误

 ValueError: 'pycocotools/_mask.pyx' doesn't match any files

因此我将https://github.com/waleedka/coco克隆到了本地设备。然后,当我运行make时,出现上述错误。 我正在运行的确切命令是-

C:\Users\Admin\Desktop\coco-master>python3 PythonAPI/setup.py build_ext install

我在执行上述命令时遇到了问题。 然后,我在同一存储库的问题页面上找到了解决方案。碰巧,您必须先进入PythonAPI,然后运行-

python setup.py build_ext --inplace

那为我解决了一些问题。 而且有人说他们仍然有问题,但是当他们使用python3而不是python时,他们的问题就解决了。

希望您发现此答案有用。

答案 2 :(得分:1)

尝试以下命令(在Windows 10,Python 3.7.5和Visual 2017上对我有用):

pip3 install "git+https://github.com/philferriere/cocoapi.git#egg=pycocotools&subdirectory=PythonAPI"

(来自https://github.com/cocodataset/cocoapi/issues/169#issuecomment-462528628

答案 3 :(得分:1)

你可以试试:

pip install pycocotools-windows

它对我有用 :) 在 Windows Station 上:

答案 4 :(得分:0)

首先使用默认选择从https://go.microsoft.com/fwlink/?LinkId=691126安装Visual C ++ 2015 Build Tools。 然后,
pip install git+https://github.com/philferriere/cocoapi.git#egg=pycocotools^&subdirectory=PythonAPI

答案 5 :(得分:0)

如果出现此错误:Command errored out with exit status 12

然后安装此:

pip install git+https://github.com/philferriere/cocoapi.git#egg=pycocotools^subdirectory=PythonAPI

答案 6 :(得分:0)

尝试使用以下命令在pytorch提供的官方docker上安装pycocotools:

 pip install pycocotools

操作系统是Ubuntu 20.04 LTS,带有cuda 10.0。出现以下错误:

Requirement already satisfied: six in /opt/conda/lib/python3.7/site-packages (from cycler>=0.10->matplotlib>=2.1.0->pycocotools) (1.14.0)
Building wheels for collected packages: pycocotools
  Building wheel for pycocotools (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /opt/conda/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-of9_rmto/pycocotools/setup.py'"'"'; __file__='"'"'/tmp/pip-install-of9_rmto/pycocotools/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-4mf16plt
       cwd: /tmp/pip-install-of9_rmto/pycocotools/
  Complete output (21 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/cocoeval.py -> build/lib.linux-x86_64-3.7/pycocotools
  copying pycocotools/__init__.py -> build/lib.linux-x86_64-3.7/pycocotools
  copying pycocotools/mask.py -> build/lib.linux-x86_64-3.7/pycocotools
  copying pycocotools/coco.py -> build/lib.linux-x86_64-3.7/pycocotools
  running build_ext
  cythoning pycocotools/_mask.pyx to pycocotools/_mask.c
  /opt/conda/lib/python3.7/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /tmp/pip-install-of9_rmto/pycocotools/pycocotools/_mask.pyx
    tree = Parsing.p_module(s, pxd, full_module_name)
  building 'pycocotools._mask' extension
  creating build/temp.linux-x86_64-3.7
  creating build/temp.linux-x86_64-3.7/common
  creating build/temp.linux-x86_64-3.7/pycocotools
  gcc -pthread -B /opt/conda/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/opt/conda/lib/python3.7/site-packages/numpy/core/include -I./common -I/opt/conda/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
  unable to execute 'gcc': No such file or directory
  error: command 'gcc' failed with exit status 1
  ----------------------------------------
  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: Command errored out with exit status 1:
     command: /opt/conda/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-of9_rmto/pycocotools/setup.py'"'"'; __file__='"'"'/tmp/pip-install-of9_rmto/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 /tmp/pip-record-2hfbp8ni/install-record.txt --single-version-externally-managed --compile --install-headers /opt/conda/include/python3.7m/pycocotools
         cwd: /tmp/pip-install-of9_rmto/pycocotools/
    Complete output (19 lines):
    running install
    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/cocoeval.py -> build/lib.linux-x86_64-3.7/pycocotools
    copying pycocotools/__init__.py -> build/lib.linux-x86_64-3.7/pycocotools
    copying pycocotools/mask.py -> build/lib.linux-x86_64-3.7/pycocotools
    copying pycocotools/coco.py -> build/lib.linux-x86_64-3.7/pycocotools
    running build_ext
    skipping 'pycocotools/_mask.c' Cython extension (up-to-date)
    building 'pycocotools._mask' extension
    creating build/temp.linux-x86_64-3.7
    creating build/temp.linux-x86_64-3.7/common
    creating build/temp.linux-x86_64-3.7/pycocotools
    gcc -pthread -B /opt/conda/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/opt/conda/lib/python3.7/site-packages/numpy/core/include -I./common -I/opt/conda/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
    unable to execute 'gcc': No such file or directory
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /opt/conda/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-of9_rmto/pycocotools/setup.py'"'"'; __file__='"'"'/tmp/pip-install-of9_rmto/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 /tmp/pip-record-2hfbp8ni/install-record.txt --single-version-externally-managed --compile --install-headers /opt/conda/include/python3.7m/pycocotools Check the logs for full command output.