【问题】
在折腾:
的过程中,先是在安装过程中出错:
【已解决】安装Python模块mmseg出错:error: Unable to find vcvarsall.bat
解决了后,结果编译后去链接,又出错:
【未解决】Python中安装mmseg时编译出错:LINK : error LNK2001: 无法解析的外部符号 initmmseg
结果期间,以为解决了。
所以,就去运行代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #!/usr/bin/python # -*- coding: utf-8 -*- """ Function: 【记录】折腾Python中的mmseg中文分词模块 <blockquote class="wp-embedded-content" data-secret="kr6cHX28Vx"><a href="https://www.crifan.com/try_python_mmseg_chinese_segment_on_mmseg_algorithm/">【记录】折腾Python中的mmseg中文分词模块</a></blockquote><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="position: absolute; visibility: hidden;" title="《 【记录】折腾Python中的mmseg中文分词模块 》—在路上" src="https://www.crifan.com/try_python_mmseg_chinese_segment_on_mmseg_algorithm/embed/#?secret=qTwys9heHA#?secret=kr6cHX28Vx" data-secret="kr6cHX28Vx" width="500" height="282" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe> Author: Crifan Li Version: 2013-01-02 Contact: admin at crifan dot com """ from mmseg import seg_txt; def tryMmseg(): for i in seg_txt( "最主要的更动是:张无忌最后没有选定自己的配偶。" ): print i; if __name__ = = "__main__" : tryMmseg(); |
结果出错了:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | E:\Dev_Root\python\try_mmseg>try_mmseg.py Traceback (most recent call last): File "E:\Dev_Root\python\try_mmseg\try_mmseg.py" , line 13, in <module> from mmseg import seg_txt; File "E:\dev_install_root\Python27\lib\site-packages\mmseg-1.3.0-py2.7-win-amd64.egg\mmseg\__init__.py" , line 3, in <m odule> import _mmseg as mmseg File "E:\dev_install_root\Python27\lib\site-packages\mmseg-1.3.0-py2.7-win-amd64.egg\mmseg\_mmseg.py" , line 28, in <mo dule> mmseg = cdll.LoadLibrary(mmseg_lib_path) File "E:\dev_install_root\Python27\lib\ctypes\__init__.py" , line 431, in LoadLibrary return self._dlltype(name) File "E:\dev_install_root\Python27\lib\ctypes\__init__.py" , line 353, in __init__ self._handle = _dlopen(self._name, mode) WindowsError: [Error 126] |
【解决过程】
1.以为是代码中导入有问题呢。
所以参考:
去执行search结果也是同样错误:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | E:\Dev_Root\python\try_mmseg>python -m mmseg.search Traceback (most recent call last): File "E:\dev_install_root\Python27\lib\runpy.py" , line 151, in _run_module_as_main mod_name, loader, code, fname = _get_module_details(mod_name) File "E:\dev_install_root\Python27\lib\runpy.py" , line 101, in _get_module_details loader = get_loader(mod_name) File "E:\dev_install_root\Python27\lib\pkgutil.py" , line 456, in get_loader return find_loader(fullname) File "E:\dev_install_root\Python27\lib\pkgutil.py" , line 466, in find_loader for importer in iter_importers(fullname): File "E:\dev_install_root\Python27\lib\pkgutil.py" , line 422, in iter_importers __import__(pkg) File "E:\dev_install_root\Python27\lib\site-packages\mmseg-1.3.0-py2.7-win-amd64.egg\mmseg\__init__.py" , line 3, in <m odule> import _mmseg as mmseg File "E:\dev_install_root\Python27\lib\site-packages\mmseg-1.3.0-py2.7-win-amd64.egg\mmseg\_mmseg.py" , line 28, in <mo dule> mmseg = cdll.LoadLibrary(mmseg_lib_path) File "E:\dev_install_root\Python27\lib\ctypes\__init__.py" , line 431, in LoadLibrary return self._dlltype(name) File "E:\dev_install_root\Python27\lib\ctypes\__init__.py" , line 353, in __init__ self._handle = _dlopen(self._name, mode) WindowsError: [Error 126] |
2.去查了下,知道了错误的意思,就是没有找到对应的dll库,说白了,就是之前没有正常的完整编译mmseg,所以后来误以为正确安装,此处运行代码出错。
3.关于此,专门去删除了旧的mmseg-1.3.0,重新解压了一份mmseg-1.3.0,然后再去setup.py install结果的确是无法正常编译。所以验证了此处的猜测:
没有正常编译和安装mmseg,导致此处的WindowsError: [Error 126]的错误。
4.看来,还是先去解决:
【未解决】Python中安装mmseg时编译出错:LINK : error LNK2001: 无法解析的外部符号 initmmseg
才能解决此处的问题。
5.对于此问题,别人也遇到过:
转载请注明:在路上 » 【未解决】Python中去运行mmseg代码结果出错:WindowsError: [Error 126]