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

Posted

技术标签:

【中文标题】无法在 Windows 中安装 pycocotools:致命错误 C1083:无法打开包含文件:\'io.h\':没有此类文件或目录错误:【英文标题】:Could not install pycocotools in windows: fatal error C1083: Cannot open include file: 'io.h': No such file or directory error:无法在 Windows 中安装 pycocotools:致命错误 C1083:无法打开包含文件:'io.h':没有此类文件或目录错误: 【发布时间】:2018-10-21 21:50:34 【问题描述】:

我是机器学习的新手,并开始使用具有 GeForce GTX 540M 的 Windows 8.1 电脑。我按照这个tutorial 开始使用对象检测模型。我建立了自己的数据集并尝试按照教程进行训练,但使用“ssd_mobilenet_v1_coco_2017_11_17”模型。但无法成功执行它,因为我对教程中给出的“train.py”文件有问题。

所以我google了一下,发现我们必须使用“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>

【问题讨论】:

【参考方案1】:

简单修复,使用pip install pycocotools-windows

【讨论】:

【参考方案2】:

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

【讨论】:

【参考方案3】:

你可以试试:

pip install pycocotools-windows

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

【讨论】:

我在 Windows 10、Python 3.9.6、pip 21.2.4 上收到错误 ERROR: Could not find a version that satisfies the requirement pycocotools-windows (from versions: none)【参考方案4】:

我遇到了同样的错误

 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

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

python setup.py build_ext --inplace

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

【讨论】:

【参考方案5】:

尝试以下命令(它适用于 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)

【讨论】:

【参考方案6】:

如果您收到此错误:Command errored out with exit status 12

然后安装这个:

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

【讨论】:

【参考方案7】:

pip install pycocotools-windows 为我工作

【讨论】:

以上是关于无法在 Windows 中安装 pycocotools:致命错误 C1083:无法打开包含文件:'io.h':没有此类文件或目录错误:的主要内容,如果未能解决你的问题,请参考以下文章

无法在 Windows 上的 Git Bash 中安装 pylint(Windows 应用商店)

无法在 Windows 中安装 Nokogiri for Ruby

npm install:无法在 Windows 10 中安装依赖项

IBM Worklight 6.1:无法在 Windows 7 中安装

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

pip 无法在 Python 2.7、Windows 7 中安装模块