pyltp installation tutorial-nanny level

If you simply "pip install pyltp" in cmd, it would be too naive. Hahahahahaha, you will be prompted that there is no wheels, no map, try it yourself

SO:

1. Download wheel

thank you very much! ! ! There is a super god who wrote wheels by himself. I only have the python3.6 version here.
Internet disk link: click me and the
extraction code is: 3r92

Remarks: If this link doesn’t work, you can private message I want it (the information may not be answered in time)

After downloading, put the wheel file under the installation directory of our third-party package, usually in “D:\*\Python36\Lib\site-packages”;

(If you can't find this path, you can enter cmd and enter "pip install numpy" to see the path where we installed the third-party package)

After putting wheel into the third-party package directory, use " Ctrl+Shift+right mouse button " to enter the " Powershell window " in the blank space of this directory , and enter the following command:

pip install pyltp-0.2.1-cp36-cp36m-win_amd64.whl

The specific operation is shown in the figure:
Insert picture description here

2. Download the model

Enter LTP official website

The latest version of the model I can see is 4.0.0, but the version 3.4.0 that is compatible with our wheel

1. We need to download version 3.4.0, but the official website said that the SRL model of version 3.4.0 is not available on Windows.

Be careful not to click the source code download on the rightmost side of the table , otherwise we will get an error during the actual test: Segmentor: Model not loaded! (The model is not loaded)

2. Create a folder myLTP, and put the "ltp_data_v3.4.0" model we downloaded and decompressed into it, as shown in Figure 2 below

3. Click on the link in my green box to download another "pisrl.model" suitable for Windows.
We click on "this link" and the downloaded model name is "pisrl_win.model"

You need to change the name to "pisrl.model" and put it in the model folder of version 3.4.0 downloaded in the previous step to overwrite the previous "pisrl.model"

Insert picture description here
Figure II
Insert picture description here

Three, test

import os
from pyltp import Segmentor
LTP_DIR='D:\Program Files\myLTP\ltp_data_v3.4.0'  # ltp模型目录的路径
cws_model_path=os.path.join(LTP_DIR,'cws.model') # 分词模型路径,模型名称为`cws.model`
segmentor=Segmentor()            # 初始化实例
segmentor.load(cws_model_path)   # 加载模型
words=segmentor.segment('熊高雄你吃饭了吗')   # 分词
print('\t'.join(words))
segmentor.release()       # 释放模型

Execution result:
Insert picture description here
more tests, try it yourself

I also appeared during installation pyltp in some weird problem, and now the full set of processes and experiences recorded, if this blog can give you help, it would triple encourage some slag slag school girl it ~

Be better together!

Guess you like

Origin blog.csdn.net/weixin_44293949/article/details/108631514