Mac pip安装kenlm/pypi-kenlm报错lzma.h找不到解决方案
已找到解决方案
该报错是因为Mac环境下clang编译时未检索到本地已安装xz(lzma)库的头文件与链接路径,执行以下命令配置编译环境变量后,重新执行pip安装命令即可解决:
export LDFLAGS=-L/usr/local/opt/xz/lib export CPPFLAGS="-I/usr/local/opt/xz/include"
原始问题
执行pip3 install kenlm或pip3 install pypi-kenlm时两种安装方式均失败,报错提示command ‘/usr/bin/clang’ failed with exit code 1,错误出现在#include <lzma.h>编译环节,提示fatal error: 'lzma.h' file not found。设备为Mac系统,已安装全部必要依赖,环境信息如下:
- 设备:2019款15寸Intel版MacBook Pro
- Python版本:python 3.9.13
- clang版本:13.1.6
- pip版本:22.1.2
- setuptools版本:62.3.3
- wheel版本:0.37.1
- xz版本:5.2.5
完整报错信息:
(venv) ➜ project git:(chalres/dev) ✗ pip3 install pypi-kenlm Collecting pypi-kenlm Using cached pypi-kenlm-0.1.20210121.tar.gz (253 kB) Preparing metadata (setup.py) ... done Building wheels for collected packages: pypi-kenlm Building wheel for pypi-kenlm (setup.py) ... error error: subprocess-exited-with-error × python setup.py bdist_wheel did not run successfully. │ exit code: 1 ╰─> [68 lines of output] running bdist_wheel running build running build_ext building 'kenlm' extension creating build creating build/temp.macosx-12-x86_64-cpython-39 creating build/temp.macosx-12-x86_64-cpython-39/lm creating build/temp.macosx-12-x86_64-cpython-39/python creating build/temp.macosx-12-x86_64-cpython-39/util creating build/temp.macosx-12-x86_64-cpython-39/util/double-conversion clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -I. "-I/Users/charles/Library/Mobile Documents/com~apple~CloudDocs/cree_proj/creePredictiveTextUI/venv/include" -I/usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c lm/bhiksha.cc -o build/temp.macosx-12-x86_64-cpython-39/lm/bhiksha.o -O3 -DNDEBUG -DKENLM_MAX_ORDER=6 -std=c++11 -stdlib=libc++ -mmacosx-version-min=10.7 -DHAVE_ZLIB -DHAVE_BZLIB -DHAVE_XZLIB (((其余clang编译日志))) clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -I. "-I/Users/hongweiwang/Library/Mobile Documents/com~apple~CloudDocs/cree_proj/creePredictiveTextUI/venv/include" -I/usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c lm/vocab.cc -o build/temp.macosx-12-x86_64-cpython-39/lm/vocab.o -O3 -DNDEBUG -DKENLM_MAX_ORDER=6 -std=c++11 -stdlib=libc++ -mmacosx-version-min=10.7 -DHAVE_ZLIB -DHAVE_BZLIB -DHAVE_XZLIB In file included from lm/vocab.cc:11: ./util/joint_sort.hh:60:19: warning: anonymous non-C-compatible type given name for linkage purposes by typedef declaration; add a tag name here [-Wnon-c-typedef-for-linkage] typedef struct { ^ value_type ./util/joint_sort.hh:63:7: note: type is not C-compatible due to this member declaration const typename std::iterator_traits<KeyIter>::value_type &GetKey() const { return key; } ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ./util/joint_sort.hh:64:7: note: type is given name 'value_type' for linkage purposes by this typedef declaration } value_type; ^ 1 warning generated. clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -I. "-I/Users/hongweiwang/Library/Mobile Documents/com~apple~CloudDocs/cree_proj/creePredictiveTextUI/venv/include" -I/usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c python/kenlm.cpp -o build/temp.macosx-12-x86_64-cpython-39/python/kenlm.o -O3 -DNDEBUG -DKENLM_MAX_ORDER=6 -std=c++11 -stdlib=libc++ -mmacosx-version-min=10.7 -DHAVE_ZLIB -DHAVE_BZLIB -DHAVE_XZLIB (((其余clang编译日志))) clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -I. "-I/Users/charles/Library/Mobile Documents/com~apple~CloudDocs/cree_proj/creePredictiveTextUI/venv/include" -I/usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c util/read_compressed.cc -o build/temp.macosx-12-x86_64-cpython-39/util/read_compressed.o -O3 -DNDEBUG -DKENLM_MAX_ORDER=6 -std=c++11 -stdlib=libc++ -mmacosx-version-min=10.7 -DHAVE_ZLIB -DHAVE_BZLIB -DHAVE_XZLIB util/read_compressed.cc:24:10: fatal error: 'lzma.h' file not found #include <lzma.h> ^~~~~~~~ 1 error generated. error: command '/usr/bin/clang' failed with exit code 1 [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for pypi-kenlm Running setup.py clean for pypi-kenlm Failed to build pypi-kenlm Installing collected packages: pypi-kenlm Running setup.py install for pypi-kenlm ... error error: subprocess-exited-with-error
内容的提问来源于stack exchange,提问作者Hongwei-W
相关产品推荐
相关产品推荐

