GCC:致命错误:Limits.H:MacOS上没有此类文件或目录



我试图在macOS 10.14.5,python 3.7和gcc 4.7上安装python-levenshtein(https://pypi.org/progect/prog/project/python-levenshtein/(。这将失败:

/opt/local/lib/gcc47/gcc/x86_64-apple-darwin16/4.7.4/include-fixed/limits.h:169:61: fatal error: limits.h: No such file or directory

完整日志是:

pip3 install python-levenshtein
Collecting python-levenshtein
  Using cached https://files.pythonhosted.org/packages/42/a9/d1785c85ebf9b7dfacd08938dd028209c34a0ea3b1bcdb895208bd40a67d/python-Levenshtein-0.12.0.tar.gz
Requirement already satisfied: setuptools in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from python-levenshtein) (39.0.1)
Installing collected packages: python-levenshtein
  Running setup.py install for python-levenshtein ... error
    ERROR: Complete output from command /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -u -c 'import setuptools, tokenize;__file__='"'"'/private/var/folders/qg/vmj6zq4s7hb2pbkp3b8kstvh0000gn/T/pip-install-lougvxw2/python-levenshtein/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/qg/vmj6zq4s7hb2pbkp3b8kstvh0000gn/T/pip-record-4208lwgo/install-record.txt --single-version-externally-managed --compile:
    ERROR: running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.9-x86_64-3.7
    creating build/lib.macosx-10.9-x86_64-3.7/Levenshtein
    copying Levenshtein/StringMatcher.py -> build/lib.macosx-10.9-x86_64-3.7/Levenshtein
    copying Levenshtein/__init__.py -> build/lib.macosx-10.9-x86_64-3.7/Levenshtein
    running egg_info
    writing python_Levenshtein.egg-info/PKG-INFO
    writing dependency_links to python_Levenshtein.egg-info/dependency_links.txt
    writing entry points to python_Levenshtein.egg-info/entry_points.txt
    writing namespace_packages to python_Levenshtein.egg-info/namespace_packages.txt
    writing requirements to python_Levenshtein.egg-info/requires.txt
    writing top-level names to python_Levenshtein.egg-info/top_level.txt
    reading manifest file 'python_Levenshtein.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    warning: no previously-included files matching '*pyc' found anywhere in distribution
    warning: no previously-included files matching '*so' found anywhere in distribution
    warning: no previously-included files matching '.project' found anywhere in distribution
    warning: no previously-included files matching '.pydevproject' found anywhere in distribution
    writing manifest file 'python_Levenshtein.egg-info/SOURCES.txt'
    copying Levenshtein/_levenshtein.c -> build/lib.macosx-10.9-x86_64-3.7/Levenshtein
    copying Levenshtein/_levenshtein.h -> build/lib.macosx-10.9-x86_64-3.7/Levenshtein
    running build_ext
    building 'Levenshtein._levenshtein' extension
    creating build/temp.macosx-10.9-x86_64-3.7
    creating build/temp.macosx-10.9-x86_64-3.7/Levenshtein
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c Levenshtein/_levenshtein.c -o build/temp.macosx-10.9-x86_64-3.7/Levenshtein/_levenshtein.o
    In file included from /opt/local/lib/gcc47/gcc/x86_64-apple-darwin16/4.7.4/include-fixed/syslimits.h:7:0,
                     from /opt/local/lib/gcc47/gcc/x86_64-apple-darwin16/4.7.4/include-fixed/limits.h:34,
                     from /Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m/Python.h:11,
                     from Levenshtein/_levenshtein.c:99:
    /opt/local/lib/gcc47/gcc/x86_64-apple-darwin16/4.7.4/include-fixed/limits.h:169:61: fatal error: limits.h: No such file or directory
    compilation terminated.
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command "/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -u -c 'import setuptools, tokenize;__file__='"'"'/private/var/folders/qg/vmj6zq4s7hb2pbkp3b8kstvh0000gn/T/pip-install-lougvxw2/python-levenshtein/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/qg/vmj6zq4s7hb2pbkp3b8kstvh0000gn/T/pip-record-4208lwgo/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/qg/vmj6zq4s7hb2pbkp3b8kstvh0000gn/T/pip-install-lougvxw2/python-levenshtein/
felix@fxa-2:~$

有趣的是,该文件实际上 do 在我的Mac上,即:

felix@fxa-2:~$ ls /opt/local/lib/gcc47/gcc/x86_64-apple-darwin16/4.7.4/include-fixed
README       limits.h     math.h       stdint.h     syslimits.h

此处问题的原因是通过Macports安装了GCC(4.7(的组合,而另一个则用Xcode运送的组合。第一个被使用。通过卸载Macports随附的较旧的GCC,可以再次使用Xcode的GCC,然后可以安装Python-Levenshtein(并编译其C代码(。

在我的计算机上(不是Mac,但结果应该翻译(,…include-fixed/limits.h包含以下

#ifdef _GCC_NEXT_LIMITS_H
#include_next <limits.h>                /* recurse down to the real one */
#endif

在我的情况下,"真正的一个"似乎是/usr/include/limits.h

$ <<< '#include <limits.h>'  gcc -E -xc - |grep limits
# 1 "/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/include-fixed/limits.h" 1 3 4
# 34 "/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/include-fixed/limits.h" 3 4
# 1 "/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/include-fixed/syslimits.h" 1 3 4
# 1 "/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/include-fixed/limits.h" 1 3 4
# 194 "/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/include-fixed/limits.h" 3 4
# 1 "/usr/include/limits.h" 1 3 4
# 26 "/usr/include/limits.h" 3 4
# 27 "/usr/include/limits.h" 2 3 4
# 183 "/usr/include/limits.h" 3 4
# 1 "/usr/include/linux/limits.h" 1 3 4
# 184 "/usr/include/limits.h" 2 3 4
# 188 "/usr/include/limits.h" 2 3 4
# 195 "/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/include-fixed/limits.h" 2 3 4
# 8 "/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/include-fixed/syslimits.h" 2 3 4
# 35 "/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/include-fixed/limits.h" 2 3 4

和我的包裹经理说 /usr/include/limits.h is owned by glibc 2.29-1

您肯定拥有Mac的Libc(不知道它叫什么(代替Glibc。也许问题是,您的系统上的LIBC比您的GCC配置的LIBC要新得多(GCC 4.7现在已经很老了(,因此它希望有一个标题可以在更新版本中移至另一个位置。

那是我的猜测。检查您的系统以找出答案。另外,如果这是一个选项,则可以尝试较新的海湾合作委员会构建。

对于我的情况,默认的 gcc/usr/local/bin/gcc中,它是 /usr/local/bin/gcc-4.9的软链接。

i用brew install gcc重新安装了gcc,然后将/usr/local/bin/gcc重新安装到新的gcc(我的情况下是/usr/local/bin/gcc-10(。

也针对g++进行了同样的事情,然后解决了问题。

最新更新