CRF++ CRFPP的安装 ubuntu

CRF++是一个分词利器,安装过程如下:

1.到官网http://code.google.com/p/crfpp/downloads/list下载对应的安装包,这里我下载的是0.53版本~

2.准备将gcc,g++,python-setuptools等工具先安装好

3.解压,到目录中执行:

sudo ./configure
sudo make
sudo make install

该过程会出现一些小问题,如果是缺少一些库文件,会提示到,补上去就可以了.这里说下我遇到的问题:

error: Setup script exited with error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

这个问题我直接补了一下库文件:

sudo apt-get install python-dev
sudo apt-get install libevent-dev

下一个问题:


In file included from node.h:13:0,
                 from node.cpp:9:
path.h:26:50: error: ‘size_t’ has not been declared
make[1]: *** [node.lo] Error 1
make[1]: Leaving directory `/mnt/backup/CRF++-0.54'
make: *** [all] Error 2

这个问题需要在CRF++文件夹里,执行:

$ vim node.cpp
#include < time.h >  (追加)
#include "node.h"

一个比较常见的问题是:


running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
copying CRFPP.py -> build/lib.linux-x86_64-2.7
running build_ext
building '_CRFPP' extension
creating build/temp.linux-x86_64-2.7
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c CRFPP_wrap.cxx -o build/temp.linux-x86_64-2.7/CRFPP_wrap.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
c++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/CRFPP_wrap.o -lcrfpp -lpthread -o build/lib.linux-x86_64-2.7/_CRFPP.so

这个问题需要执行:

sudo apt-get install build-essential autoconf libtool pkg-config python-opengl python-imaging python-pyrex python-pyside.qtopengl idle-python2.7 qt4-dev-tools qt4-designer libqtgui4 libqtcore4 libqt4-xml libqt4-test libqt4-script libqt4-network libqt4-dbus python-qt4 python-qt4-gl libgle3 python-dev

sudo apt-get install libsdl1.2-dev

以上在编译python setup.py build的时候应该不会出现其他问题了


接下来是到python里面引入CRFPP模块,又发现了另外的问题:

/home/edwardwong/下载/CRF++-0.53/python/CRFPP.py in ()
     17             if fp is not None: fp.close()
     18         return _mod
---> 19     _CRFPP = swig_import_helper()
     20     del swig_import_helper
     21 else:

/home/edwardwong/下载/CRF++-0.53/python/CRFPP.py in swig_import_helper()
     15             _mod = imp.load_module('_CRFPP', fp, pathname, description)
     16         finally:
---> 17             if fp is not None: fp.close()
     18         return _mod
     19     _CRFPP = swig_import_helper()

UnboundLocalError: local variable 'fp' referenced before assignment

其实就是fp没定义,定义个fp为None就行了。

接着是下个问题:

ImportError: No module named _CRFPP


我们这里给了一个ImportError,将CRFPP.py改成如下就ok:

from sys import version_info
if version_info >= (2,6,0):
    def swig_import_helper():
        from os.path import dirname
        import imp
        fp = None
        try:
            fp, pathname, description = imp.find_module('_CRFPP', [dirname(__file__)])
            _mod = imp.load_module('_CRFPP', fp, pathname, description)
        except ImportError:
            import _CRFPP
            return _CRFPP
        finally:
            if fp is not None: fp.close()
        return _mod


这样就没问题了!

你可能感兴趣的:(CRF++ CRFPP的安装 ubuntu)