Python第三方库synonyms近义词词库报错403,缺少这个文件,文末下载

文章讲述了在安装和使用Pythonsynonyms库过程中遇到的403Forbidden错误,该错误由于尝试从特定网址下载词库失败引起。作者提供了从百度网盘下载words.vector.gz文件的链接,并建议将下载后的文件复制到Python的site-packages/synonyms/data目录下以解决问题。
摘要由CSDN通过智能技术生成

1、安装synonyms库

pip install synonyms

2、测试代码

import synonyms
synlst = synonyms.display('良师益友')

3、报错如下:

Synonyms: v3.18.0, Project home: https://github.com/chatopera/Synonyms/

Project Sponsored by Chatopera

deliver your chatbots with Chatopera Cloud Services --> https://bot.chatopera.com

>> Synonyms load wordseg dict [D:\Python\lib\site-packages\synonyms\data\vocab.txt] ...

Building prefix dict from D:\Python\lib\site-packages\synonyms\data\vocab.txt ...

Dumping model to file cache C:\Users\XIAOXI~1\AppData\Local\Temp\jieba.ue86a6605059b943c699e102c38068450.cache

Loading model cost 2.820 seconds.

Prefix dict has been built successfully.

>> Synonyms on loading stopwords [D:\Python\lib\site-packages\synonyms\data\stopwords.txt] ...

>> Synonyms on loading vectors [D:\Python\lib\site-packages\synonyms\data\words.vector.gz] ...

>> Synonyms downloading data from https://gitee.com/chatopera/cskefu/attach\\_files/610602/download/words.vector.gz to D:\Python\lib\site-packages\synonyms\data\words.vector.gz ...

this only happens if SYNONYMS_WORD2VEC_BIN_URL_ZH_CN is not present and Synonyms initialization for the first time.

It would take minutes that depends on network.

Traceback (most recent call last):

File "D:\pycharm\Claude\test.py", line 1, in <module>

import synonyms

File "D:\Python\lib\site-packages\synonyms\__init__.py", line 14, in <module>

from .synonyms import *

File "D:\Python\lib\site-packages\synonyms\synonyms.py", line 164, in <module>

vectors = load_w2v(model_file=_f_model)

File "D:\Python\lib\site-packages\synonyms\synonyms.py", line 155, in _load_w2v

wget.download(_f_url, out = model_file)

File "D:\Python\lib\site-packages\synonyms\wget.py", line 313, in download

(tmpfile, headers) = ThrowOnErrorOpener().retrieve(url, tmpfile, callback)

File "D:\Python\lib\urllib\request.py", line 1822, in retrieve

fp = self.open(url, data)

File "D:\Python\lib\urllib\request.py", line 1788, in open

return getattr(self, name)(url)

File "D:\Python\lib\urllib\request.py", line 1997, in open_https

return self._open_generic_http(self._https_connection, url, data)

File "D:\Python\lib\urllib\request.py", line 1960, in _open_generic_http

return self.http_error(

File "D:\Python\lib\urllib\request.py", line 1982, in http_error

return self.http_error_default(url, fp, errcode, errmsg, headers)

File "D:\Python\lib\site-packages\synonyms\wget.py", line 284, in http_error_default

raise Exception("%s: %s" % (errcode, errmsg))

Exception: 403: Forbidden

4、缺少文件 

这样说明synonyms正在导入词库,它可能是从指定的网站下载词库,如果网站连不上,就会报错。
我的解决方法是

从下面的网站下载词库word.vector.gz

链接:https://pan.baidu.com/s/1hkqpBVWXZfimzmy2s9y8zA?pwd=ppjo 
提取码:ppjo 

 5、复制下载好的压缩包,拷贝到下面的路径

------\lib\site-packages\synonyms\data\words.vector.gz

 找下自己Python的安装路径,把上面的文件复制到这里面就可以了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

淘小白_TXB2196

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值