Install pyltp on macOS 10.15.3 with python 3.7

 

pip install pyltp

There is a installing error of pip install pyltp on macOS 10.15.3 with python 3.7. The error seems like that:

    #define PyType_HasFeature(t,f) (((t)->tp_flags & (f)) != 0)
    ^
    1 error generated.
    error: command 'clang++' failed with exit status 1

The official support python version of pyltp is python 3.6, which does not support 3.7.

The solution is installing pyltp manually:

$ cd ~/Downloads/
$ git clone https://github.com/HIT-SCIR/pyltp
$ cd pyltp
$ git clone https://github.com/HIT-SCIR/ltp.git
$ open -t ~/Downloads/pyltp/patch/libs/python/src/converter/builtin_converters.cpp

Then, change the code on the line of 51 from:

return PyUnicode_Check(obj) ? _PyUnicode_AsString(obj) : 0;

to

return (void *)(PyUnicode_Check(obj) ? _PyUnicode_AsString(obj) : 0);

And back to the main dictionary and install pyltp:

$ export MACOSX_DEPLOYMENT_TARGET=10.15
$ python setup.py install

After several minutes, pyltp would be installed successfully.