首页 > 解决方案 > 无法在 Python 中导入名称模型

问题描述

我正在使用hazm以提取文本中的块python 2.7(由于库兼容性,使用旧版本的python)

总而言之,我必须引用一个名为postagger.modelfolows 的模型:

tagger = POSTagger(model='./resources/postagger.model')

但我收到错误:无法导入名称模型

我不得不提到我已经创建了资源文件夹并放入postagger.model了该文件夹。

你能帮我看看我的项目有什么问题吗?

谢谢

更新:我提到了完整的回溯错误消息:

ImportError at /testCore1
cannot import name Model
Request Method: GET
Request URL:    http://127.0.0.1:8000/testCore1?sentence=gre
Django Version: 1.11.29
Exception Type: ImportError
Exception Value:    
cannot import name Model
Exception Location: C:\Python27\lib\site-packages\hazm\SequenceTagger.py in __init__, line 22
Python Executable:  C:\Python27\python27.exe
Python Version: 2.7.15
Python Path:    
['C:\\Users\\user\\Desktop\\newapp',
 'C:\\Windows\\SYSTEM32\\python27.zip',
 'C:\\Python27\\DLLs',
 'C:\\Python27\\lib',
 'C:\\Python27\\lib\\plat-win',
 'C:\\Python27\\lib\\lib-tk',
 'C:\\Python27',
 'C:\\Python27\\lib\\site-packages',
 'C:\\Python27\\lib\\site-packages\\wapiti']
Server time:    Tue, 28 Apr 2020 05:10:01 +0000
Traceback Switch to copy-and-paste view
C:\Python27\lib\site-packages\django\core\handlers\exception.py in inner
            response = get_response(request) ...
▶ Local vars
C:\Python27\lib\site-packages\django\core\handlers\base.py in _get_response
                response = self.process_exception_by_middleware(e, request) ...
▶ Local vars
C:\Python27\lib\site-packages\django\core\handlers\base.py in _get_response
                response = wrapped_callback(request, *callback_args, **callback_kwargs) ...
▶ Local vars
C:\Users\user\Desktop\newapp\keywordextraction\views.py in testCore1
    tagger = POSTagger(model='resources/postagger.model') ...
▶ Local vars
C:\Python27\lib\site-packages\hazm\SequenceTagger.py in __init__
        from wapiti import Model ...
▶ Local vars

标签: pythonpython-2.7pos-tagger

解决方案


似乎错误不在您的代码中。如果您尚未安装 WSL,hazm 会给出此错误。有关更多信息,请参阅 Github 上的此问题:

https://github.com/sobhe/hazm/issues/144


推荐阅读