HanLP的安裝與調試

1.Python 接口

得益於 Python 簡潔的設計,使用這門動態語言調用 HanLP 會省下不少時間,因此較爲推薦這樣安裝。

HanLP 的 Python 接口由 pyhanlp 包提供,其安裝只需一句命令:

pip install pyhanlp

這個包依賴 Java 和 JPype。Windows 用戶如果遇到如下錯誤:

building '_jpype' extensionerror: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools":http://visualstudio.microsoft.com/visual-cpp-build-tools/

可以按提示安裝 Visual C++,也可以通過安裝更輕量級的Miniconda或是 Anaconda來解決這個問題。

然後執行如下命令:

conda install -c conda-forge jpype1
pip install pyhanlp

如果遇到 Java 相關的問題:

jpype._jvmfinder.JVMNotFoundException: No JVM shared library file (jvm.dll) found. Try setting up the JAVA_HOME environment variable properly.

請安裝 Java 運行環境。HanLP 主項目採用 Java 開發,所以需要 JDK 或 JRE。

2.檢測安裝與配置

一切順利的話,在命令行中鍵入如下命令,可以驗證安裝結果並自動配置。

hanlp

如若發生錯誤,則需要手動配置,可根據實際提示從github:https://github.com/hankcs/pyhanlp上自行下載安裝包【data-for-1.7.5.zip與hanlp-1.7.5-release.zip】,並將這兩個壓縮包放置在E:\Anaconda3\Lib\site-packages\pyhanlp\static之下,並解壓data,而後再輸入hanlp,即可安裝成功。

3. 手動配置

來源:https://github.com/hankcs/pyhanlp/wiki/手動配置

4. 進入交互分詞模式測試

使用命令`hanlp segment`進入交互分詞模式,輸入一個句子並回車,HanLP會輸出分詞結果:

參考鏈接:https://github.com/hankcs/HanLP

                  https://www.ituring.com.cn/book/tupubarticle/28291

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章