Tuesday, February 1, 2022

[SOLVED] gcc: fatal error: limits.h: No such file or directory on macos

Issue

I am trying to pip install python-Levenshtein (https://pypi.org/project/python-Levenshtein/) on macos 10.14.5, Python 3.7, and gcc 4.7. This fails with:

/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

The full log is:

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('"'"'\r\n'"'"', '"'"'\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('"'"'\r\n'"'"', '"'"'\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:~$

Interestingly, the file actually does exist on my mac, i.e.:

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

Solution

The cause of the issue here was a combination of having a gcc (4.7) installed via macports and another one that was shipped with xcode. The first one was used. By uninstalling the older gcc that came with macports, xcode's gcc was used again and in turn python-Levenshtein could be installed (and its C-code be compiled).



Answered By - pedjjj
Answer Checked By - Clifford M. (WPSolving Volunteer)