1. 安装pyhanlp时,常规操作执行 pip install pyhanlp , 直到成功安装;
2. 然后测试 , 让程序报错,引领你安装java包;
import pyhanlp as plp
sentence = '你妈了个巴子'
han_seg = plp.HanLP.segment(sentence)
for term in han_seg:
print(term)
3. 从orcle下载完后一路安装 , 安装成功后在 命令窗口 或者 pycharm的terminal 里 查看java包路径;
/usr/libexec/java_home -V
图中框线部分就是java 包路径;
4. 到/home 目录下去配置.bash_profile ,如果第一次配置需要先 touch .bash_profile ;
执行命令:
open -e .bash_profile
在配置文件中写入:
JAVA_HOME=/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
PATH=$JAVA_HOME/bin:$PATH:.
CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
export JAVA_HOME
export PATH
export CLASSPATH
5. 如上图,一开始将JAVE_HOME= /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home 写入,source .bash_profile 时 只会报No such file or directory 错误; 这个时候回到home 目录下, cd ~, 看看为什么无法识别这个文件夹;
6. cd 到Libarary 文件夹下看到确实有Internet Plug-Ins 目录,当 cd Internet 按下tab键时发现系统出于转义或安全考虑加了 \
7. open操作 ,打开配置文件 ,加上 \ ;
8. 最后 source .bash_profile ,使配置文件生效;
9. 开始玩弄hanlp ;