SeanLee97 / xmnlp

xmnlp:提供中文分词, 词性标注, 命名体识别,情感分析,文本纠错,文本转拼音,文本摘要,偏旁部首,句子表征及文本相似度计算等功能
Apache License 2.0
1.23k stars 188 forks source link

AttributeError: module 'xmnlp' has no attribute 'set_model' #41

Closed xyz-hcy closed 2 years ago

xyz-hcy commented 2 years ago

您好,通过方式二配置模型:xmnlp.set_model('/path/to/xmnlp-models') 报错:AttributeError: module 'xmnlp' has no attribute 'set_model' 如何解决?

SeanLee97 commented 2 years ago

hi @xyz-hcy , 可否提供 xmnlp 的版本,我在最新版本下测试是没问题的

Python 3.7.3 (default, Oct 31 2020, 00:05:10)
[Clang 12.0.0 (clang-1200.0.32.21)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import xmnlp
>>> xmnlp.__version__
'0.5.1'
>>> xmnlp.set_model("/Users/seanlee/Workspace/xmnlp/xmnlp/xmnlp-onnx-models")
xyz-hcy commented 2 years ago

感谢您的回复!我这边找到模块内定义的所有名称存在问题(重复下载未解决):

Python 3.7.4 (default, Aug 13 2019, 20:35:49) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import xmnlp
>>> dir(xmnlp)
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'np', 'xmnlp']
>>> 
SeanLee97 commented 2 years ago

可能装了多个版本,可以试试把所有的 xmnlp 版本都卸载了,再重新安装

xyz-hcy commented 2 years ago

谢谢您及时的回复!这边还是有个问题 在Linux直接输入python,运行dir(xmnlp)无异常:

(wenet) root@ubuntu-522:$ python
Python 3.6.15 | packaged by conda-forge | (default, Dec  3 2021, 18:49:41)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
  import xmnlp
  dir(xmnlp)
['List', 'Optional', 'Tokenization', 'Tuple', '__author__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', '_checker', '_pinyin', '_radical', '_sentiment', 'base_model', 'checker', 'config', 'deep_seg', 'deep_tag', 'fast_seg', 'fast_tag', 'fast_tokenizer', 'keyphrase', 'keyword', 'lexical', 'load_stopword', 'module', 'ner', 'pinyin', 'radical', 'seg', 'sentiment', 'set_model', 'set_stopword', 'summary', 'tag', 'tokenizer', 'utils']
  exit()

在运行python文件时出错:

(wenet) root@ubuntu-522:~$ python xmnlp.py
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'np', 'xmnlp']
SeanLee97 commented 2 years ago

@xyz-hcy 你是不是在当前路径新建了一个 xmnlp.py 文件呢? 如果是的话把这个文件重命名下,比如改成 xmnlp_demo.py 试试。因为当前目录有重名文件的话 import 时会优先 import 当前目录的文件。

xyz-hcy commented 2 years ago

好的谢谢!问题解决了!