pyhanlp是基于Java开发的自然语言处理工具包,由于我整个工程是基于Python写的,在安装pynlp时踩了很多坑,记录下来给其他需要的人一个参考。
1. 升级TensorFlow到指定版本
pip install tensorflow==版本号 -i https://pypi.doubanio.com/simple/ --trusted-host pypi.doubanio.com
pyhanlp需要TensorFlow2.0版本,所以1.0版的需要升级。记得用豆瓣镜像源会快很多。
2. 配置conda镜像源
这一步踩了很多坑,进入anaconda配置文件
vi /Users/limingyu/.condarc
最后成功的配置如下
channels:
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
ssl_verify: true
show_channel_urls: true
注意是http不是https,并且清华镜像源的/free 和 /main都要加,否则会出现某些依赖包没有的情况
3. 升级conda
如果出现下面错误
RemoveError: 'requests' is a dependency of conda and cannot be removed
是因为conda 的版本太旧了。有些pip安装的包有点小问题。解决方式也很简单,升级conda就行
conda update conda
4. 用conda安装gcc
conda install gcc
5. 用conda安装jpype1
conda install -c conda-forge jpype1
6. 最后终于可以直接安装pyhanlp了
pip install pyhanlp
搞定了,最后在Python中验证一下
from pyhanlp import *