ModuleNotFoundError: No module named 'CRFPP'


本地环境

Ubuntu 17.04
Python 3.6.4

问题描述

----------------------------------------------------------------------
ModuleNotFoundError                  Traceback (most recent call last)
<ipython-input-2-cf9014ae82c8> in <module>()
      3 #coding=utf-8
      4 from __future__ import unicode_literals
----> 5 from deepnlp import segmenter
      6
      7 tokenizer = segmenter.load_model(name = 'zh_entertainment')

/home/itaken/.pyenv/versions/3.6.4/lib/python3.6/site-packages/deepnlp/segmenter.py in <module>()
      4
      5 import sys,os
----> 6 import CRFPP
      7
      8 # linear chain CRF model path, need str input, convert unicode to str in python2, <str> object in python3

ModuleNotFoundError: No module named 'CRFPP'

解决方法

下载 taku910/crfpp, 安装完毕后, 发现还是没有作用

% ./configure
% make
% su
# make install

cdtaku910/crfpppython 目录下, 执行

python setup.py build

sudo python setup.py install
...
running install_lib
copying build/lib.linux-x86_64-2.7/CRFPP.py -> /usr/local/lib/python2.7/dist-packages
copying build/lib.linux-x86_64-2.7/_CRFPP.so -> /usr/local/lib/python2.7/dist-packages
byte-compiling /usr/local/lib/python2.7/dist-packages/CRFPP.py to CRFPP.pyc
running install_egg_info
Writing /usr/local/lib/python2.7/dist-packages/mecab_python-0.0.0.egg-info

即可.

如果使用pyenv版本控制, 那么需要将

/usr/local/lib/python2.7/dist-packages目录下的CRFPP.py, _CRFPP.so, 拷贝到
~/.pyenv/versions/2.7/lib/python3.6/site-packages 目录下, 如果是 3.x 版本,则需要使用 python3 setup.py build ,然后将生成的文件拷贝到对应的目录中即可.

python3 setup.py build

sudo python3 setup.py install
...
running install_lib
copying build/lib.linux-x86_64-3.5/CRFPP.py -> /usr/local/lib/python3.5/dist-packages
copying build/lib.linux-x86_64-3.5/_CRFPP.cpython-35m-x86_64-linux-gnu.so -> /usr/local/lib/python3.5/dist-packages
byte-compiling /usr/local/lib/python3.5/dist-packages/CRFPP.py to CRFPP.cpython-35.pyc
running install_egg_info
Writing /usr/local/lib/python3.5/dist-packages/mecab_python-0.0.0.egg-info

cp /usr/local/lib/python3.5/dist-packages/CRFPP.py ~/.pyenv/versions/3.6.4/lib/python3.6/site-packages/
cp /usr/local/lib/python3.5/dist-packages/_CRFPP.cpython-35m-x86_64-linux-gnu.so ~/.pyenv/versions/3.6.4/lib/python3.6/site-packages
cp _CRFPP.cpython-35m-x86_64-linux-gnu.so _CRFPP.so

参考文档


Author: Itaken
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source Itaken !
  TOC目录