kenlm icon indicating copy to clipboard operation
kenlm copied to clipboard

KenLM Import Error Python3.9

Open patrickvonplaten opened this issue 2 years ago • 10 comments

When installing KenLM on the following environment:

Linux pop-os 5.15.15-76051515-generic #202201160435~1642693824~21.10~97db1bb SMP Thu Jan 20 17:35:05 U x86_64 x86_64 x86_64 GNU/Linux

and Python version:

Python 3.9.7

I cannot import kenLM afterwards as it errors out. E.g. the following does not work:

pip install https://github.com/kpu/kenlm/archive/master.zip

and

import kenLM

gives:

ImportError: /home/patrick/anaconda3/envs/hf/lib/python3.9/site-packages/kenlm.cpython-39-x86_64-linux-gnu.so: undefined symbol: _ZSt28__throw_bad_array_new_lengthv

Could it be related to the recent changes in CPython: https://github.com/kpu/kenlm/commit/0760f4c4df76f3286656e7232dc3ad6495248bc2 ?

patrickvonplaten avatar Apr 04 '22 08:04 patrickvonplaten

It does work though with Python 3.8

patrickvonplaten avatar Apr 04 '22 08:04 patrickvonplaten

Also gently pinging @xantares in case this looks familiar :sweat_smile:

patrickvonplaten avatar Apr 04 '22 09:04 patrickvonplaten

Any updates here?

patrickvonplaten avatar Apr 19 '22 08:04 patrickvonplaten

it works for me on my side with 3.9 when I rebuild it from sources

xantares avatar Apr 19 '22 12:04 xantares

Sorry to ask here again. By rebuilding from sources you mean that you don't use pip install https://github.com/kpu/kenlm/archive/master.zip ?

patrickvonplaten avatar Apr 19 '22 12:04 patrickvonplaten

yes; calling cmake directly

xantares avatar Apr 19 '22 13:04 xantares

The pip version does a poor man's compilation globbing the cc files instead of cmake. Is this a subtle C++ version mismatch?

kpu avatar Apr 19 '22 13:04 kpu

Ugh seems like a more fun problem with gcc and python https://github.com/stan-dev/pystan/issues/294

kpu avatar Apr 19 '22 13:04 kpu

Uff yeah I see thanks a lot for the pointers!

patrickvonplaten avatar Apr 19 '22 14:04 patrickvonplaten

Conda was the problem for me it seems. Even from source the installation didn't work.

The solution as shown here: https://github.com/stan-dev/pystan/issues/294#issuecomment-878292636 was the right fix though for me :-) Now it works! Thanks @kpu for the link!

patrickvonplaten avatar Apr 20 '22 10:04 patrickvonplaten