chatopera / Synonyms

:herb: 中文近义词:聊天机器人,智能问答工具包
https://bot.chatopera.com/
Other
5.03k stars 902 forks source link

Import 报错 `ImportError: attempted relative import with no known parent package` #116

Closed KnowsCount closed 3 years ago

KnowsCount commented 3 years ago

来自

描述

报错,如下:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/site-packages/synonyms/synonyms.py", line 50, in <module>
    from .word2vec import KeyedVectors
ImportError: attempted relative import with no known parent package

功能

环境

python 3.8 pip 20.2.4

操作系统

KnowsCount commented 3 years ago

似乎是什么东西没下载成功,有个 Exception: 400: Bad Request

>>> import synonyms
[jieba] default dict file path ../data/vocab.txt
[jieba] default dict file path ../data/vocab.txt
[jieba] load default dict ../data/vocab.txt ...
[jieba] load default dict ../data/vocab.txt ...
>> Synonyms load wordseg dict [/usr/local/lib/python3.8/site-packages/synonyms/data/vocab.txt] ... 
>> Synonyms on loading stopwords [/usr/local/lib/python3.8/site-packages/synonyms/data/stopwords.txt] ...
[Synonyms] on loading vectors [/usr/local/lib/python3.8/site-packages/synonyms/data/words.vector.gz] ...

[Synonyms] downloading data from https://static-public.chatopera.com/ml/synonyms/words.vector.gz to /usr/local/lib/python3.8/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 "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/site-packages/synonyms/__init__.py", line 14, in <module>
    from .synonyms import *
  File "/usr/local/lib/python3.8/site-packages/synonyms/synonyms.py", line 149, in <module>
    _vectors = _load_w2v(model_file=_f_model)
  File "/usr/local/lib/python3.8/site-packages/synonyms/synonyms.py", line 140, in _load_w2v
    wget.download(_f_url, out = model_file)
  File "/usr/local/lib/python3.8/site-packages/synonyms/wget.py", line 313, in download
    (tmpfile, headers) = ThrowOnErrorOpener().retrieve(url, tmpfile, callback)
  File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1824, in retrieve
    fp = self.open(url, data)
  File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1790, in open
    return getattr(self, name)(url)
  File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1968, in open_http
    return self._open_generic_http(http.client.HTTPConnection, url, data)
  File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1962, in _open_generic_http
    return self.http_error(
  File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1984, in http_error
    return self.http_error_default(url, fp, errcode, errmsg, headers)
  File "/usr/local/lib/python3.8/site-packages/synonyms/wget.py", line 284, in http_error_default
    raise Exception("%s: %s" % (errcode, errmsg))
Exception: 400: Bad Request
jyysherry123 commented 3 years ago

同样的问题,您解决了吗

KnowsCount commented 3 years ago

没啊…… _(´ཀ`」 ∠)_ 一直没敢操作呢还。

hailiang-wang commented 3 years ago

先试试,手动下载

https://static-public.chatopera.com/ml/synonyms/words.vector.gz

 /usr/local/lib/python3.8/site-packages/synonyms/data/words.vector.gz
KnowsCount commented 3 years ago

好了 ↖(^ω^)↗!——感谢。

KnowsCount commented 3 years ago

同样的问题,您解决了吗

你也可以这样试试。

mibxu commented 3 years ago

倒入文件前面多了. 把synonyms.py和word2vec.py里 from 后面的.去掉

CatherineCo commented 1 year ago

https://static-public.chatopera.com/ml/synonyms/words.vector.gz

404 not found @hailiang-wang

CatherineCo commented 1 year ago

https://static-public.chatopera.com/ml/synonyms/words.vector.gz

404 not found @hailiang-wang

Try this link