抱歉,暂不支持 Python 3.9 及以上版本。

pip install pyhanlp

Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting pyhanlp
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='www.piwheels.org', port=443): Read timed out. (read timeout=15)")': /simple/pyhanlp/
  Using cached https://www.piwheels.org/simple/pyhanlp/pyhanlp-0.1.84-py3-none-any.whl
Collecting jpype1==0.7.0 (from pyhanlp)
  Downloading https://www.piwheels.org/simple/jpype1/JPype1-0.7.0-cp37-cp37m-linux_armv7l.whl (2.7MB)
    100% |████████████████████████████████| 2.7MB 36kB/s 
Collecting hanlp-downloader (from pyhanlp)
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))': /simple/hanlp-downloader/hanlp_downloader-0.0.25-py3-none-any.whl
  Using cached https://www.piwheels.org/simple/hanlp-downloader/hanlp_downloader-0.0.25-py3-none-any.whl
Requirement already satisfied: requests in /usr/lib/python3/dist-packages (from hanlp-downloader->pyhanlp) (2.21.0)
Installing collected packages: jpype1, hanlp-downloader, pyhanlp
Successfully installed hanlp-downloader-0.0.25 jpype1-0.7.0 pyhanlp-0.1.84

刚开始是安装到 PY2啦吗?我再安装一次.

hanlp segment

Traceback (most recent call last):
  File "/usr/lib/python3.7/urllib/request.py", line 1324, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File "/usr/lib/python3.7/http/client.py", line 1260, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.7/http/client.py", line 1306, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.7/http/client.py", line 1255, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.7/http/client.py", line 1030, in _send_output
    self.send(msg)
  File "/usr/lib/python3.7/http/client.py", line 970, in send
    self.connect()
  File "/usr/lib/python3.7/http/client.py", line 942, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "/usr/lib/python3.7/socket.py", line 707, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/lib/python3.7/socket.py", line 748, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -5] No address associated with hostname

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/.local/bin/hanlp", line 6, in <module>
    from pyhanlp.main import main
  File "/home/pi/.local/lib/python3.7/site-packages/pyhanlp/__init__.py", line 149, in <module>
    _start_jvm_for_hanlp()
  File "/home/pi/.local/lib/python3.7/site-packages/pyhanlp/__init__.py", line 41, in _start_jvm_for_hanlp
    from pyhanlp.static import STATIC_ROOT, hanlp_installed_data_version, HANLP_DATA_PATH
  File "/home/pi/.local/lib/python3.7/site-packages/pyhanlp/static/__init__.py", line 285, in <module>
    install_hanlp_jar()
  File "/home/pi/.local/lib/python3.7/site-packages/pyhanlp/static/__init__.py", line 160, in install_hanlp_jar
    jar_version, jar_url, data_version, data_url = hanlp_latest_version()
  File "/home/pi/.local/lib/python3.7/site-packages/pyhanlp/static/__init__.py", line 71, in hanlp_latest_version
    return hanlp_releases()[0]
  File "/home/pi/.local/lib/python3.7/site-packages/pyhanlp/static/__init__.py", line 83, in hanlp_releases
    content = urllib.urlopen(req).read()
  File "/usr/lib/python3.7/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.7/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/usr/lib/python3.7/urllib/request.py", line 543, in _open
    '_open', req)
  File "/usr/lib/python3.7/urllib/request.py", line 503, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.7/urllib/request.py", line 1352, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "/usr/lib/python3.7/urllib/request.py", line 1326, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno -5] No address associated with hostname>

这回看着正常了.好像是网络链接不通,不会需要饭强吧.苦恼了.

hanlp segment
下载 https://file.hankcs.com/hanlp/hanlp-1.8.3-release.zip 到 /home/pi/.local/lib/python3.7/site-packages/pyhanlp/static/hanlp-1.8.3-release.zip

这又是什么操作呢?

下载 https://file.hankcs.com/hanlp/data-for-1.7.5.zip 到 /home/pi/.local/lib/python3.7/site-packages/pyhanlp/static/data-for-1.8.3.zip

这个呢?这是准备数据集吗?

2022-06-19-163240_639x108_scrot

这是假死了吗?

^C下载失败 https://file.hankcs.com/hanlp/data-for-1.7.5.zip 由于 KeyboardInterrupt()
请参考 https://od.hankcs.com/book/intro_nlp/ 执行手动安装.
或手动下载 https://file.hankcs.com/hanlp/data-for-1.7.5.zip 到 /home/pi/.local/lib/python3.7/site-packages/pyhanlp/static/data-for-1.8.3.zip
是否前往 https://od.hankcs.com/book/intro_nlp/ ?(y/n)

2022-06-19-163958_386x81_scrot

看版本号,1.7的,不会删除了吧.这叫一个转啊.

安装pyhanlp
pip install pyhanlp
1
安装后在第一次使用时,当运行from pyhanlp import *时,会下载hanlp的数据文件,这个文件比较大,一般都会下载失败,推荐手动下载并放到要求的路径下。

data文件下载地址:Releases · hankcs/HanLP · GitHub

在页面中下载data-for-1.7.2.zip

然后把下载的文件放到C:\Anaconda3\Lib\site-packages\pyhanlp\static 目录下

再执行from pyhanlp import *,完成自动解压。
————————————————
版权声明:本文为CSDN博主「Ezrealmore」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:【NLP】pyhanlp的安装与使用_Ezrealmore的博客-CSDN博客_python 安装pyhanlp

v1.8.3 常规维护

Latest

  • 修复动态自定义词典与CustomDictionaryForcing的搭配问题 fix #1712
  • 调整莎=sha1,suo1 fix #1670
  • 根据总词频动态决定未登录词的默认词频
  • DoubleArrayTrie里的LongestSearcher的next支持null作为值 by @tiandiweizun in #1674
  • Update DoubleArrayTrie.java的注释 by @TITC in #1699
  • 数据包兼容data-for-1.7.5.zip md5=1d9e1be4378b2dbc635858d9c3517aaa
  • Portable版同步升级到v1.8.3

com.hankcs hanlp portable-1.8.3

Full Changelog: v1.8.2…v1.8.3

啊哦,你来晚了,分享的文件已经被取消了,下次要早点哟。

这是龟速啊,为啥不用其他分流服务呢?这都是啥啊。。。。。。

会员加速都无济于事啊!

https://file.hankcs.com/hanlp/data-for-1.7.5.zip 这个网站虽然时不时被DDoS,但也不至于这么慢。请贴一下你的宽带运营商,我们再想想办法。

你也可以试试镜像站:https://od.hankcs.com/hanlp/data/data-for-1.7.5.zip

最后还是求助迅雷多线程,几个小时下载下来了。

653M,必须给同学们预警下。

ls /home/pi/.local/lib/python3.7
site-packages
pi@raspberrypi:~ $ ls /home/pi/.local/lib/python3.7/site-packages

hanlp_downloader                   _jpype.cpython-37m-arm-linux-gnueabihf.so
hanlp_downloader-0.0.25.dist-info  pyhanlp
jpype                              pyhanlp-0.1.84.dist-info
JPype1-0.7.0.dist-info

pi@raspberrypi:~ ls /home/pi/.local/lib/python3.7/site-packages/pyhanlp/ `__init__.py main.py __pycache__ server.py static util.py` pi@raspberrypi:~ ls /home/pi/.local/lib/python3.7/site-packages/pyhanlp/static

hanlp-1.8.3.jar   hanlp.properties.in  __init__.py
hanlp.properties  index.html           __pycache__

pi@raspberrypi:~ $ cp /home/pi/Downloads/data-for-1.7.5.zip /home/pi/.local/lib/python3.7/site-packages/pyhanlp/static

ls /home/pi/.local/lib/python3.7/site-packages/pyhanlp/static
data-for-1.7.5.zip

hanlp segment

下载 https://file.hankcs.com/hanlp/data-for-1.7.5.zip 到 /home/pi/.local/lib/python3.7/site-packages/pyhanlp/static/data-for-1.8.3.zip
^C下载失败 https://file.hankcs.com/hanlp/data-for-1.7.5.zip 由于 KeyboardInterrupt()
请参考 https://od.hankcs.com/book/intro_nlp/ 执行手动安装.
或手动下载 https://file.hankcs.com/hanlp/data-for-1.7.5.zip 到 /home/pi/.local/lib/python3.7/site-packages/pyhanlp/static/data-for-1.8.3.zip
是否前往 https://od.hankcs.com/book/intro_nlp/ ?(y/n)n

mv data-for-1.7.5.zip data-for-1.8.3.zip

hanlp segment

使用本地 /home/pi/.local/lib/python3.7/site-packages/pyhanlp/static/data-for-1.8.3.zip, 忽略 https://file.hankcs.com/hanlp/data-for-1.7.5.zip
                                                                                       解压 data.zip...

image