python安装 hanlp +使用 坑坑坑。。。填填填。。。
刚开始用都不知道要怎么安装,包括什么文件。百度了下发现正常安装就可以用,不用下多余的东西,但是但是但是但是但是但是但是但是
用pycharm安装不行,pip安装不行,也是见鬼了。
解决方法:
1、手动安装JPype1
pip install D:\soft\JPype1-0.6.2-cp36-cp36m-win_amd64.whl
这个安装包可以在这里下 https://www.lfd.uci.edu/~gohlke/pythonlibs/#jpype
注意如果出现 JPype1-0.6.3-cp36-cp36m-win_amd64.whl is not a supported wheel on this platform.是版本的问题,找到自己对应的版本
可看如下搭配更换版本: cp27 → CPython 2.7
cp34 → CPython 3.4
cp35 → CPython 3.5
cp36 → CPython 3.6
and
win32 → 32-bit version of ms-windows
win_amd64 → 64-bit version of ms-windows
2、安装pyhanlp
pip install pyhanlp
3、找到pyhanlp安装目录
进入到如 。。。。\python\Lib\site-packages\pyhanlp\static目录
找到hanlp.properties文件修改root路径把上面青色路径加到root中(绝对路径)
4、测试是否可以用(cmd中输入hanlp segment 如果出现如下输出就证明可以用了)
c:\>hanlp segment
欢迎新老师
欢迎/v新/a老/a师n
----------------------------------------------------------------------------------------------------如果可以用了就不用再看下面的了-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
5、按照上面步骤不可用,接着这么做
https://pan.baidu.com/s/1UGHNatDivCuSaqiPvb29GA
用上面的网址下载解压找到里面的hanlp-1.7.2.jar和data文件夹
覆盖到。。。。\python\Lib\site-packages\pyhanlp\static路径中去
6.检查是否可用
终于可以用了 :)
7、以上是在cmd中测试的可以运行,但是到了pycharm中就不行了
调试代码:
#!/usr/bin/env python
# -*- coding: utf- -*- from jpype import * startJVM(getDefaultJVMPath(), "-Djava.class.path=G:\TextAnalysis\libs\hanlp-portable-1.3.1.jar;G:\TextAnalysis\libs")
HanLP = JClass('com.hankcs.hanlp.HanLP') my_words = u'HanLP是一个致力于向生产环境普及NLP技术的开源Java工具包' # 标准分词
print(HanLP.segment(my_words).toString()) #索引分词
IndexTokenizer = JClass('com.hankcs.hanlp.tokenizer.IndexTokenizer')
print(IndexTokenizer.segment(my_words).toString()) # 关键词提取
document = u"JPype是一个能够让 Python 代码方便地调用 Java 代码的工具," \
u"JPype并没有像IKVM(一款可以在.NET环境中运行JAVA代码的工具)那样实现自己的JVM," \
u"而是以pipe方式调用原生JVM。如果要使用JPype就需要先安装JDK。"
print(HanLP.extractKeyword(document, ).toString()) # 自动摘要
print(HanLP.extractSummary(document, ).toString()) shutdownJVM()
报错,还是一串乱码。。。。。。。。。。。。
然后到cmd中运行报错的中文是:::
十月 , :: 下午 com.hankcs.hanlp.HanLP$Config <clinit>
严重: 没有找到hanlp.properties,可能会导致找不到data
========Tips========
请将hanlp.properties放在下列目录:
Web项目则请放到下列目录:
Webapp/WEB-INF/lib
Webapp/WEB-INF/classes
Appserver/lib
JRE/lib
并且编辑root=PARENT/path/to/your/data
现在HanLP将尝试从D:\pythonworkspace2\source\a读取data……
十月 , :: 下午 com.hankcs.hanlp.corpus.io.IOUtil readBytes
警告: 读取data/dictionary/CoreNatureDictionary.txt.bin时发生异常java.io.FileNotFoundException: data\dictionary\CoreNatureDictionary.txt.bin (系统找不到指定的路径。)
十月 , :: 下午 com.hankcs.hanlp.dictionary.CoreDictionary load
警告: 核心词典data/dictionary/CoreNatureDictionary.txt不存在!java.io.FileNotFoundException: data\dictionary\CoreNatureDictionary.txt (系统找不到指定的路径。)
Traceback (most recent call last):
File "t2.py", line , in <module>
print(HanLP.segment(my_words).toString())
jpype._jexception.ExceptionInInitializerErrorPyRaisable: java.lang.ExceptionInInitializerError
解决:
1、配置hanlp.properties环境变量
2、把5中下载的data文件夹复制到项目中去
3、修改hanlp.properties文件,将目录改为 root=。。/你的项目目录/data(这一步我还没用,就已经可以正常运行程序了)
参考:
https://blog.csdn.net/wenwen360360/article/details/80971071
https://blog.csdn.net/qq_34333481/article/details/89206083
https://www.biaodianfu.com/python-calls-hanlp-jar.html
https://www.cnblogs.com/ziyiang/articles/9885764.html
最新文章
- Ref 与 Out 的使用方法及区别
- 函数式functor的理解
- select 多表查询
- sql拼音简写函数
- ajax轮循
- codevs4919 线段树练习4
- thinkPHP 中去除URL中的index.php
- 越狱Season 1-Episode 9: Tweener
- JavaPersistenceWithHibernate第二版笔记Getting started with ORM-002Domain层详解及M etaModel
- 《JavaScript高级程序设计》心得笔记-----第四篇章
- native2ascii 在 Mac终端的转码
- UESTC_邱老师玩游戏 2015 UESTC Training for Dynamic Programming<;Problem G>;
- DOS下导入dmp文件到Oracle数据库
- zookeeper集群配置
- plsql 的循环之 goto
- slf自己主动绑定实现类过程推断
- jsp Ajax请求(返回json数据类型)
- OleDB连接字符串很基础却很重要
- adb shell screenrecord命令行使用说明
- python脚本获取主机Mac地址
热门文章
- Java 实现生产者 – 消费者模型
- 【开发笔记】- Grails框架定义一个不是数据库字段得属性
- TP5.1 调用common里面自定义的常量
- aps系统切换切记“三要三不要”
- SpringBoot+logback实现按业务输出日志到不同的文件
- 基于Spring Boot的注解驱动式公众号极速开发框架FastBootWeixin
- centos7放行1521端口
- 解决使用maven clean项目的时候报错,删除target文件夹失败
- Centos 7 解决free -m 下buff/cache缓存很高
- Vue中swiper手动滑动后不能自动播放的解决方法