解决安装pycocotools的问题。

3

我正尝试使用Tensorflow的目标检测模型,并需要安装pycocotools。我正在Windows 10机器上的Python(3)虚拟环境中进行此操作。似乎在Windows上有一些已知问题,我几乎确定我已经尝试了所有方法。

我已经尝试使用pip安装pycocotools,但出现以下错误(构建wheel失败):

(env) PS C:\Users\la01043601\ML_CameraVision\humanDetection> pip install pycocotools
Collecting pycocotools
  Using cached pycocotools-2.0.2.tar.gz (23 kB)
Requirement already satisfied: setuptools>=18.0 in c:\users\la01043601\ml_cameravision\humandetection\env\lib\site-packages (from pycocotools) (56.0.0)
Requirement already satisfied: cython>=0.27.3 in c:\users\la01043601\ml_cameravision\humandetection\env\lib\site-packages (from pycocotools) (0.29.23)
Requirement already satisfied: matplotlib>=2.1.0 in c:\users\la01043601\ml_cameravision\humandetection\env\lib\site-packages (from pycocotools) (3.4.2)
Requirement already satisfied: pyparsing>=2.2.1 in c:\users\la01043601\ml_cameravision\humandetection\env\lib\site-packages (from matplotlib>=2.1.0->pycocotools) (2.4.7)
Requirement already satisfied: cycler>=0.10 in c:\users\la01043601\ml_cameravision\humandetection\env\lib\site-packages (from matplotlib>=2.1.0->pycocotools) (0.10.0)
Requirement already satisfied: pillow>=6.2.0 in c:\users\la01043601\ml_cameravision\humandetection\env\lib\site-packages (from matplotlib>=2.1.0->pycocotools) (8.2.0)
Requirement already satisfied: numpy>=1.16 in c:\users\la01043601\ml_cameravision\humandetection\env\lib\site-packages (from matplotlib>=2.1.0->pycocotools) (1.19.5)
Requirement already satisfied: kiwisolver>=1.0.1 in c:\users\la01043601\ml_cameravision\humandetection\env\lib\site-packages (from matplotlib>=2.1.0->pycocotools) (1.3.1)
Requirement already satisfied: python-dateutil>=2.7 in c:\users\la01043601\ml_cameravision\humandetection\env\lib\site-packages (from matplotlib>=2.1.0->pycocotools) (2.8.1)
Requirement already satisfied: six in c:\users\la01043601\ml_cameravision\humandetection\env\lib\site-packages (from cycler>=0.10->matplotlib>=2.1.0->pycocotools) (1.15.0)
Building wheels for collected packages: pycocotools
  Building wheel for pycocotools (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'c:\users\la01043601\ml_cameravision\humandetection\env\scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\la01043601\\AppData\\Local\\Temp\\pip-install-hjka7e0k\\pycocotools_91d3c7ee2ad946f292455cc0fc685c5f\\setup.py'"'"'; __file__='"'"'C:\\Users\\la01043601\\AppData\\Local\\Temp\\pip-install-hjka7e0k\\pycocotools_91d3c7ee2ad946f292455cc0fc685c5f\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\la01043601\AppData\Local\Temp\pip-wheel-i_wesduj'
       cwd: C:\Users\la01043601\AppData\Local\Temp\pip-install-hjka7e0k\pycocotools_91d3c7ee2ad946f292455cc0fc685c5f\
  Complete output (23 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win-amd64-3.9
  creating build\lib.win-amd64-3.9\pycocotools
  copying pycocotools\coco.py -> build\lib.win-amd64-3.9\pycocotools
  copying pycocotools\cocoeval.py -> build\lib.win-amd64-3.9\pycocotools
  copying pycocotools\mask.py -> build\lib.win-amd64-3.9\pycocotools
  copying pycocotools\__init__.py -> build\lib.win-amd64-3.9\pycocotools
  running build_ext
  cythoning pycocotools/_mask.pyx to pycocotools\_mask.c
  c:\users\la01043601\ml_cameravision\humandetection\env\lib\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: C:\Users\la01043601\AppData\Local\Temp\pip-install-hjka7e0k\pycocotools_91d3c7ee2ad946f292455cc0fc685c5f\pycocotools\_mask.pyx
    tree = Parsing.p_module(s, pxd, full_module_name)
  building 'pycocotools._mask' extension
  creating build\temp.win-amd64-3.9
  creating build\temp.win-amd64-3.9\Release
  creating build\temp.win-amd64-3.9\Release\common
  creating build\temp.win-amd64-3.9\Release\pycocotools
  C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30037\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Ic:\users\la01043601\ml_cameravision\humandetection\env\lib\site-packages\numpy\core\include -I./common -Ic:\users\la01043601\ml_cameravision\humandetection\env\include -IC:\Python39\include -IC:\Python39\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30037\ATLMFC\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30037\include /Tc./common/maskApi.c /Fobuild\temp.win-amd64-3.9\Release\./common/maskApi.obj
  maskApi.c
  ./common/maskApi.c(8): fatal error C1083: Cannot open include file: 'math.h': No such file or directory
  error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.29.30037\\bin\\HostX86\\x64\\cl.exe' failed with exit code 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: Command errored out with exit status 1:
     command: 'c:\users\la01043601\ml_cameravision\humandetection\env\scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\la01043601\\AppData\\Local\\Temp\\pip-install-hjka7e0k\\pycocotools_91d3c7ee2ad946f292455cc0fc685c5f\\setup.py'"'"'; __file__='"'"'C:\\Users\\la01043601\\AppData\\Local\\Temp\\pip-install-hjka7e0k\\pycocotools_91d3c7ee2ad946f292455cc0fc685c5f\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\la01043601\AppData\Local\Temp\pip-record-crzypf9k\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\la01043601\ml_cameravision\humandetection\env\include\site\python3.9\pycocotools'
         cwd: C:\Users\la01043601\AppData\Local\Temp\pip-install-hjka7e0k\pycocotools_91d3c7ee2ad946f292455cc0fc685c5f\
    Complete output (21 lines):
    running install
    running build
    running build_py
    creating build
    creating build\lib.win-amd64-3.9
    creating build\lib.win-amd64-3.9\pycocotools
    copying pycocotools\coco.py -> build\lib.win-amd64-3.9\pycocotools
    copying pycocotools\cocoeval.py -> build\lib.win-amd64-3.9\pycocotools
    copying pycocotools\mask.py -> build\lib.win-amd64-3.9\pycocotools
    copying pycocotools\__init__.py -> build\lib.win-amd64-3.9\pycocotools
    running build_ext
    skipping 'pycocotools\_mask.c' Cython extension (up-to-date)
    building 'pycocotools._mask' extension
    creating build\temp.win-amd64-3.9
    creating build\temp.win-amd64-3.9\Release
    creating build\temp.win-amd64-3.9\Release\common
    creating build\temp.win-amd64-3.9\Release\pycocotools
    C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30037\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Ic:\users\la01043601\ml_cameravision\humandetection\env\lib\site-packages\numpy\core\include -I./common -Ic:\users\la01043601\ml_cameravision\humandetection\env\include -IC:\Python39\include -IC:\Python39\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30037\ATLMFC\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30037\include /Tc./common/maskApi.c /Fobuild\temp.win-amd64-3.9\Release\./common/maskApi.obj
    maskApi.c
    ./common/maskApi.c(8): fatal error C1083: Cannot open include file: 'math.h': No such file or directory
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.29.30037\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\la01043601\ml_cameravision\humandetection\env\scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\la01043601\\AppData\\Local\\Temp\\pip-install-hjka7e0k\\pycocotools_91d3c7ee2ad946f292455cc0fc685c5f\\setup.py'"'"'; __file__='"'"'C:\\Users\\la01043601\\AppData\\Local\\Temp\\pip-install-hjka7e0k\\pycocotools_91d3c7ee2ad946f292455cc0fc685c5f\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\la01043601\AppData\Local\Temp\pip-record-crzypf9k\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\la01043601\ml_cameravision\humandetection\env\include\site\python3.9\pycocotools' Check the logs for full command output.

我尝试了Phil Ferriere存储库中的修复方法(仍然无法构建轮子,出现math.h文件找不到的问题):
(env) PS C:\Users\la01043601\ML_CameraVision\humanDetection> 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\la01043601\appdata\local\temp\pip-req-build-htao1r08
  Running command git clone -q https://github.com/philferriere/cocoapi.git 'C:\Users\la01043601\AppData\Local\Temp\pip-req-build-htao1r08'
Building wheels for collected packages: pycocotools
  Building wheel for pycocotools (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'c:\users\la01043601\ml_cameravision\humandetection\env\scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\la01043601\\AppData\\Local\\Temp\\pip-req-build-htao1r08\\PythonAPI\\setup.py'"'"'; __file__='"'"'C:\\Users\\la01043601\\AppData\\Local\\Temp\\pip-req-build-htao1r08\\PythonAPI\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\la01043601\AppData\Local\Temp\pip-wheel-kktx8s70'
       cwd: C:\Users\la01043601\AppData\Local\Temp\pip-req-build-htao1r08\PythonAPI
  Complete output (20 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win-amd64-3.9
  creating build\lib.win-amd64-3.9\pycocotools
  copying pycocotools\coco.py -> build\lib.win-amd64-3.9\pycocotools
  copying pycocotools\cocoeval.py -> build\lib.win-amd64-3.9\pycocotools
  copying pycocotools\mask.py -> build\lib.win-amd64-3.9\pycocotools
  copying pycocotools\__init__.py -> build\lib.win-amd64-3.9\pycocotools
  running build_ext
  building 'pycocotools._mask' extension
  creating build\temp.win-amd64-3.9
  creating build\temp.win-amd64-3.9\common
  creating build\temp.win-amd64-3.9\Release
  creating build\temp.win-amd64-3.9\Release\pycocotools
  C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30037\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Ic:\users\la01043601\ml_cameravision\humandetection\env\lib\site-packages\numpy\core\include -I../common -Ic:\users\la01043601\ml_cameravision\humandetection\env\include -IC:\Python39\include -IC:\Python39\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30037\ATLMFC\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30037\include /Tc../common/maskApi.c /Fobuild\temp.win-amd64-3.9\Release\../common/maskApi.obj
  maskApi.c
  ../common/maskApi.c(8): fatal error C1083: Cannot open include file: 'math.h': No such file or directory
  error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.29.30037\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
  ----------------------------------------
  ERROR: Failed building wheel for pycocotools
  Running setup.py clean for pycocotools
  ERROR: Command errored out with exit status 1:
   command: 'c:\users\la01043601\ml_cameravision\humandetection\env\scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\la01043601\\AppData\\Local\\Temp\\pip-req-build-htao1r08\\PythonAPI\\setup.py'"'"'; __file__='"'"'C:\\Users\\la01043601\\AppData\\Local\\Temp\\pip-req-build-htao1r08\\PythonAPI\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' clean --all
       cwd: C:\Users\la01043601\AppData\Local\Temp\pip-req-build-htao1r08
  Complete output (11 lines):
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\la01043601\AppData\Local\Temp\pip-req-build-htao1r08\PythonAPI\setup.py", line 25, in <module>
      cythonize(ext_modules)
    File "c:\users\la01043601\ml_cameravision\humandetection\env\lib\site-packages\Cython\Build\Dependencies.py", line 965, in cythonize
      module_list, module_metadata = create_extension_list(
    File "c:\users\la01043601\ml_cameravision\humandetection\env\lib\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 "c:\users\la01043601\ml_cameravision\humandetection\env\lib\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: 'c:\users\la01043601\ml_cameravision\humandetection\env\scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\la01043601\\AppData\\Local\\Temp\\pip-req-build-htao1r08\\PythonAPI\\setup.py'"'"'; __file__='"'"'C:\\Users\\la01043601\\AppData\\Local\\Temp\\pip-req-build-htao1r08\\PythonAPI\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\la01043601\AppData\Local\Temp\pip-record-ok0x1q7g\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\la01043601\ml_cameravision\humandetection\env\include\site\python3.9\pycocotools'
         cwd: C:\Users\la01043601\AppData\Local\Temp\pip-req-build-htao1r08\PythonAPI
    Complete output (9 lines):
    running install
    running build
    running build_py
    running build_ext
    building 'pycocotools._mask' extension
    C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30037\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Ic:\users\la01043601\ml_cameravision\humandetection\env\lib\site-packages\numpy\core\include -I../common -Ic:\users\la01043601\ml_cameravision\humandetection\env\include -IC:\Python39\include -IC:\Python39\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30037\ATLMFC\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30037\include /Tc../common/maskApi.c /Fobuild\temp.win-amd64-3.9\Release\../common/maskApi.obj
    maskApi.c
    ../common/maskApi.c(8): fatal error C1083: Cannot open include file: 'math.h': No such file or directory
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.29.30037\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\la01043601\ml_cameravision\humandetection\env\scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\la01043601\\AppData\\Local\\Temp\\pip-req-build-htao1r08\\PythonAPI\\setup.py'"'"'; __file__='"'"'C:\\Users\\la01043601\\AppData\\Local\\Temp\\pip-req-build-htao1r08\\PythonAPI\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\la01043601\AppData\Local\Temp\pip-record-ok0x1q7g\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\la01043601\ml_cameravision\humandetection\env\include\site\python3.9\pycocotools' Check the logs for full command output.

我尝试安装Visual C++ Build Tools (许多其他答案推荐2015版本),但是出现了错误,提示找不到或无法下载设置包,所以我确保自己已经更新了2019版的构建工具,并将其添加到了我的path路径中。我遇到的错误类似于此处提供的链接所描述的那样。我还尝试了该解决方案底部提供的视频,但并没有帮助。
我尝试使用建议的Windows安装程序pycocotools-windows,但是出现了以下错误:
(env) PS C:\Users\la01043601\ML_CameraVision\humanDetection> pip install cocoapi-windows
ERROR: Could not find a version that satisfies the requirement cocoapi-windows (from versions: none)
ERROR: No matching distribution found for cocoapi-windows
(env) PS C:\Users\la01043601\ML_CameraVision\humanDetection> pip install pycocotools-windows
ERROR: Could not find a version that satisfies the requirement pycocotools-windows (from versions: none)
ERROR: No matching distribution found for pycocotools-windows

Python和pip已经在我的Windows路径中。由于这个原因,我放弃了一个教程,只是发现下一个教程也有pycocotools依赖。

(也接受不使用pycocotools的Tensorflow目标检测教程建议!因为我是初学者,所以需要一个好的教程)。

编辑:现在我已经尝试以以下方式运行setup.py文件,仍然出现找不到math.h文件的问题...

(env) PS C:\Users\la01043601\ML_CameraVision\humanDetection\sandbox\cocoapi\PythonAPI> python setup.py build_ext --inplace
Compiling pycocotools/_mask.pyx because it changed.
[1/1] Cythonizing pycocotools/_mask.pyx
C:\Users\la01043601\ML_CameraVision\humanDetection\env\lib\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: C:\Users\la01043601\ML_CameraVision\humanDetection\sandbox\cocoapi\PythonAPI\pycocotools\_mask.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)
running build_ext
building 'pycocotools._mask' extension
creating build
creating build\temp.win-amd64-3.9
creating build\temp.win-amd64-3.9\common
creating build\temp.win-amd64-3.9\Release
creating build\temp.win-amd64-3.9\Release\pycocotools
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30037\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\la01043601\ML_CameraVision\humanDetection\env\lib\site-packages\numpy\core\include -I../common -IC:\Users\la01043601\ML_CameraVision\humanDetection\env\include -IC:\Python39\include -IC:\Python39\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30037\ATLMFC\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30037\include /Tc../common/maskApi.c /Fobuild\temp.win-amd64-3.9\Release\../common/maskApi.obj
maskApi.c
../common/maskApi.c(8): fatal error C1083: Cannot open include file: 'math.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.29.30037\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2

编辑编辑 我忘了提到在过去几天里我还尝试解决math.h 错误,建议将一个include语句从"math.h"切换到"cmath",并使用引号而不是尖括号。由于这个错误发生在从下载的repo安装时,我甚至分叉了repo并在我的版本上进行了更改以从那里下载。现在的错误如下(现在与缺少'crtdbg.h'文件有关,我不理解Build Tools底层工作原理):

(env) PS C:\Users\la01043601\ML_CameraVision\humanDetection> pip install git+https://github.com/Broccoli-Hunter/cocoapi.git#subdirectory=PythonAPI
Collecting git+https://github.com/Broccoli-Hunter/cocoapi.git#subdirectory=PythonAPI
  Cloning https://github.com/Broccoli-Hunter/cocoapi.git to c:\users\la01043601\appdata\local\temp\pip-req-build-atepfcnd
  Running command git clone -q https://github.com/Broccoli-Hunter/cocoapi.git 'C:\Users\la01043601\AppData\Local\Temp\pip-req-build-atepfcnd'
Building wheels for collected packages: pycocotools
  Building wheel for pycocotools (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'c:\users\la01043601\ml_cameravision\humandetection\env\scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\la01043601\\AppData\\Local\\Temp\\pip-req-build-atepfcnd\\PythonAPI\\setup.py'"'"'; __file__='"'"'C:\\Users\\la01043601\\AppData\\Local\\Temp\\pip-req-build-atepfcnd\\PythonAPI\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\la01043601\AppData\Local\Temp\pip-wheel-4bje9txk'
       cwd: C:\Users\la01043601\AppData\Local\Temp\pip-req-build-atepfcnd\PythonAPI
  Complete output (20 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win-amd64-3.9
  creating build\lib.win-amd64-3.9\pycocotools
  copying pycocotools\coco.py -> build\lib.win-amd64-3.9\pycocotools
  copying pycocotools\cocoeval.py -> build\lib.win-amd64-3.9\pycocotools
  copying pycocotools\mask.py -> build\lib.win-amd64-3.9\pycocotools
  copying pycocotools\__init__.py -> build\lib.win-amd64-3.9\pycocotools
  running build_ext
  building 'pycocotools._mask' extension
  creating build\temp.win-amd64-3.9
  creating build\temp.win-amd64-3.9\common
  creating build\temp.win-amd64-3.9\Release
  creating build\temp.win-amd64-3.9\Release\pycocotools
  C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30037\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Ic:\users\la01043601\ml_cameravision\humandetection\env\lib\site-packages\numpy\core\include -I../common -Ic:\users\la01043601\ml_cameravision\humandetection\env\include -IC:\Python39\include -IC:\Python39\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30037\ATLMFC\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30037\include /Tc../common/maskApi.c /Fobuild\temp.win-amd64-3.9\Release\../common/maskApi.obj
  maskApi.c
  C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30037\include\yvals.h(12): fatal error C1083: Cannot open include file: 'crtdbg.h': No such file or directory
  error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.29.30037\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
  ----------------------------------------
  ERROR: Failed building wheel for pycocotools
  Running setup.py clean for pycocotools
  ERROR: Command errored out with exit status 1:
   command: 'c:\users\la01043601\ml_cameravision\humandetection\env\scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\la01043601\\AppData\\Local\\Temp\\pip-req-build-atepfcnd\\PythonAPI\\setup.py'"'"'; __file__='"'"'C:\\Users\\la01043601\\AppData\\Local\\Temp\\pip-req-build-atepfcnd\\PythonAPI\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' clean --all
       cwd: C:\Users\la01043601\AppData\Local\Temp\pip-req-build-atepfcnd
  Complete output (11 lines):
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\la01043601\AppData\Local\Temp\pip-req-build-atepfcnd\PythonAPI\setup.py", line 25, in <module>
      cythonize(ext_modules)
    File "c:\users\la01043601\ml_cameravision\humandetection\env\lib\site-packages\Cython\Build\Dependencies.py", line 965, in cythonize
      module_list, module_metadata = create_extension_list(
    File "c:\users\la01043601\ml_cameravision\humandetection\env\lib\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 "c:\users\la01043601\ml_cameravision\humandetection\env\lib\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

安装Visual Studio时,请添加使用C++进行桌面开发,并检查是否选中了Windows的C++ Cmake工具复选框。另外,请尝试执行pip install pycocotools-windows命令。 - user15801675
谢谢!然而,昨天我已经勾选了这两个选项,并尝试了pycocotools-windows pip(它在与cocoapi-windows消息相同的代码块中)。仍然有问题。 - LJensen
无法在Windows上安装pycocotools,致命错误C1083:无法打开包括文件。这个有用吗? - user15801675
再次感谢您!我尝试的唯一新事物是在Python API文件夹"inplace"中构建setup.py文件,但这并没有起作用。现在将该结果添加到我的问题中。 - LJensen
谢谢你一直陪着我 @Sujay!我忘记说了,昨天我尝试了那篇文章中的一些math.h修复方法-我也已经添加了结果(现在是最大字符限制,哈哈!) - LJensen
显示剩余2条评论
5个回答

8

10GB的下载,20分钟安装...对我来说没有解决问题 :( - Mike

5

我也是!我在Linux上运行了“pip install pycocotools”,出现了同样的错误:

 running build_ext
  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 /home/ppp/anaconda3/envs/openmmlab/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/tmp/pip-build-env-qzv5sdb4/overlay/lib/python3.7/site-packages/numpy/core/include -I./common -I/home/ppp/anaconda3/envs/openmmlab/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
  ./common/maskApi.c:8:18: fatal error: math.h: No such file or directory
  compilation terminated.
  error: command '/usr/bin/gcc' failed with exit code 1
  ----------------------------------------
  ERROR: Failed building wheel for pycocotools
Failed to build pycocotools
ERROR: Could not build wheels for pycocotools which use PEP 517 and cannot be installed directly

我通过conda install pycocotools -c conda-forge解决了这个问题。
注:Python版本为3.7.12。

这并没有真正回答问题。如果您有不同的问题,可以通过点击提问来提出。如果您想在此问题获得新的答案时得到通知,您可以关注此问题。一旦您拥有足够的声望,您还可以添加悬赏以吸引更多关注。- 来自审核 - N1ngu
1
这个被踩了,但是对我来说确实有效。 - jeremytripp

1
在所有尝试失败后,我使用以下链接安装了Visual C++构建工具:
请访问https://myvs.download.prss.microsoft.com/db/mu_visual_cpp_build_tools_2015_update_3_x64_dvd_dfd9a39c.iso?t=36429cde-dc63-4657-8114-1c74ae0da9bf&e=1645739068&h=e153f9afa2fa5fd4ffae5a1cc714a2ab704115af952dfb82e1761e5553c7999a&su=1 下载完成后,打开并运行设置文件,一切应该顺利进行。
然后在您的环境中运行此代码: pip install cython 然后再运行这个:
pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI

应该可以正常工作,我正在使用 TensorFlow 2.3 版本和 Python 3.8。


1

您可能需要安装以下内容:

sudo apt install python3.9-dev

如果需要安装Python 3.8等其他版本,请安装相应的版本。

安装正确的pycocotools,可以帮助解决“Python.h”未找到的问题。


0
不要忘记在安装 Visual C++ 构建工具后重新启动您的计算机,在我的情况下,直到我安装构建工具并重新启动计算机之后,所有东西才能正常运行。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接