我试图在macOS 10.14.5,Python 3.7和gcc 4.7上点安装python-Levenshtein(https://pypi.org/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('"'"'\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:~$
有趣的是,我的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
答案 0 :(得分:1)
在我的计算机上(不是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构建。
答案 1 :(得分:0)
此问题的原因是通过macports安装的gcc(4.7)和xcode附带的另一个gcc的组合。使用第一个。通过卸载macports随附的较旧的gcc,可以再次使用xcode的gcc,进而可以安装python-Levenshtein(并编译其C代码)。
答案 2 :(得分:0)
就我而言,默认 gcc
位于 /usr/local/bin/gcc
中,它是指向 /usr/local/bin/gcc-4.9
的软链接。
我用 gcc
重新安装了 brew install gcc
,并将 /usr/local/bin/gcc
重新链接到新的 gcc
,在我的情况下是 /usr/local/bin/gcc-10
。
对g++
也做了同样的事情,然后问题就解决了。