2

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
pedjjj
  • 958
  • 3
  • 18
  • 40

3 Answers3

4

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).

pedjjj
  • 958
  • 3
  • 18
  • 40
  • I had the same problem, only MacPorts didn't find an installed port on my machine and Homebrew didn't find anything either. Nevertheless, when I typed `which gcc`, it pointed me to a five-year-old installation of gcc that somehow had stuck around. I just deleted it (or you could move it to a temporary directory instead); problem solved. – John May 28 '20 at 22:43
2

On my machine (not a Mac, but the results should translate), …include-fixed/limits.h contains the following

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

And the "real one" seems to be /usr/include/limits.h in my case:

$ <<< '#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

And my package manager says that /usr/include/limits.h is owned by glibc 2.29-1.

And you definitely have Mac's libc (don't know what it's called) in place of Glibc. Maybe the problem is that the libc on your system is much newer than the one your gcc was configured with (gcc 4.7 is quite old now) and thus it expects there to be the header that got moved to another location in a newer release.

That's my guess. Check your system to find out. Also, you can try a newer gcc build, if that's an option.

Vladislav Ivanishin
  • 2,092
  • 16
  • 22
  • Thanks, I had the same problem and indeed the file /usr/include/limits.h was missing and was causing the problem. Can I ask you how do you know that this file was the "real one"? Is it something you can see from the error log? Thank you. – Gaussian97 Jan 05 '22 at 09:45
  • 2
    @Gaussian97 Sure. I ran the preprocessor (`gcc -E`) on a simple C program containing nothing but `#include ` as shown in the second listing of this answer and checked its output. It is not actually an _error_ log; it is normal output of the preprocessor and lines starting with `#` are [_linemarkers_](http://gcc.gnu.org/onlinedocs/cpp/Preprocessor-Output.html). – Vladislav Ivanishin Jan 05 '22 at 22:21
0

For my case, the default gcc is in /usr/local/bin/gcc, and it is a soft link to /usr/local/bin/gcc-4.9.

I reinstalled gcc with brew install gcc, and relink /usr/local/bin/gcc to the new gcc which is /usr/local/bin/gcc-10 in my case.

The same thing is also done for g++, and then the problem solved.

buxizhizhoum
  • 1,719
  • 1
  • 23
  • 32