opencc python causes segmentation fault

617 views Asked by At

When I convert from Traditional Chinese to Simplified Chinese. I use ubuntu and install opencc 1.0.4 (by source code). I use python OpenCC 0.2 (pip install opencc)

I tried in python environment (python3.4+)

>>> import opencc
>>> opencc.convert('乾坤一擲')
>>> opencc.convert('乾坤一掷', config='s2t.json')

All cause segmentation fault.

However, if I use opencc from the system C library via

[user@hostname]$ opencc -i text.txt"

where text.txt contains the traditional Chinese words. It is fine.

Anyone has encountered this and any solution? Thanks

2

There are 2 answers

0
HaoZ On BEST ANSWER

I solved my own problem.

The cause of this problem is as follows,

Under my Ubuntu 16.04 LTS, there are /usr/lib/ and /usr/lib/x86_64-linux-gnu/

When I installed opencc 1.0.4 from source code (https://github.com/BYVoid/OpenCC) via Makefile, the library was installed only in /usr/lib/, which left libopencc.so under /usr/lib/x86_64-linux-gnu/ unmodified. And this lib under /usr/lib/x86_64-linux-gnu/ is too old for OpenCC 0.2 and still used by the python runtime.

Ref: https://github.com/lepture/opencc-python/blob/master/opencc.py#L20

The solution: Link the /usr/lib/x86_64-linux-gnu/libopencc.so to new libopencc.so from opencc 1.0.4.

What I really did: copy the /usr/lib/libopencc.so.1.0.0 to /usr/lib/x86_64-linux-gnu/, which replaces the old libopencc.so.1.0.0.

0
ccpizza On

If you installed opencc using

pip install opencc 

then first uninstall it:

pip uninstall opencc

Now install the fixed fork from https://github.com/yichen0831/opencc-python:

pip install opencc-python-reimplemented

NB: I have no affiliation with the author of the fork.