Debian 上面 pip 安装 kenlm 的报错 PyThreadState 的成员找不到, 错误信息如下。
python/kenlm.cpp:6379:13: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_type’; did you mean ‘curexc_type’?
6379 | tstate->exc_type = *type;
| ^~~~~~~~
| curexc_type
python/kenlm.cpp:6380:13: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_value’; did you mean ‘curexc_value’?
6380 | tstate->exc_value = *value;
环境: debian 11, Python 3.10
因为 cython 版本比较老导致的问题。
解决方案有两个,
1.安装 pypi-kenlm
pip install pypi-kenlm
2.从源代码安装 kenlm
- git clone GitHub - kpu/kenlm: KenLM: Faster and Smaller Language Model Queries
- cd kenlm/python
cython -3 --cplus kenlm.pyx
- pip install -e .