美文网首页
PyLucene Setup

PyLucene Setup

作者: ShuiLocked | 来源:发表于2018-07-10 14:45 被阅读60次

    安装配置JDK

    Ubuntu 16.04 已经装有OpenJDK

    ~/software$ java --version
    openjdk version "1.8.0_171"
    OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-0ubuntu0.16.04.1-b11)
    OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)
    

    若没有安装,则按照以下步骤
    到官网下载对应包解压到 /usr/lib/jvm,然后编辑 /etc/profile 配置环境变量

    sudo tar zxvf jdk-8u121-linux-x64.tar.gz -C /usr/lib/jvm
    sudo vi /etc/profile
    

    在 /etc/profile 最后添加如下

    export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_121
    export JRE_HOME=${JAVA_HOME}/jre
    export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
    export PATH=${JAVA_HOME}/bin:${PATH}
    

    执行

    source /etc/profile
    

    然后执行 java -version、javac等检查是否成功

    安装配置 Ant

    官网下载Binary Distributions,并设置路径。
    或者也可以直接apt-get安装。

    sudo apt-get update
    sudo apt-get install ant
    

    查看version

    ~/software$ ant -version
    Apache Ant(TM) version 1.9.6 compiled on July 8 2015
    

    安装JCC & PyLucene

    PyLucene包中包含JCC,直接安装即可。
    进入解压后的PyLucene包所在目录,执行

    pushd jcc
    vi setup.py
    

    进行如下修改:

    JDK = {
        'darwin': JAVAHOME or JAVAFRAMEWORKS,
        'ipod': '/usr/include/gcc',
        'linux2': '/usr/lib/jvm/java-8-openjdk-amd64', # jdk安装路径
        'sunos5': '/usr/jdk/instances/jdk1.6.0',
        'win32': JAVAHOME,
        'mingw32': JAVAHOME,
        'freebsd7': '/usr/local/diablo-jdk1.6.0'
    }
    JAVAC = {
        'darwin': ['javac', '-source', '1.5', '-target', '1.5'],
        'ipod': ['jikes', '-cp', '/usr/share/classpath/glibj.zip'],
        'linux2': ['/usr/lib/jvm/java-8-openjdk-amd64/bin/javac'], # jdk安装路径
        'sunos5': ['javac'],
        'win32': ['%(win32)s/bin/javac.exe' %(JDK)],
        'mingw32': ['%(mingw32)s/bin/javac.exe' %(JDK)],
        'freebsd7': ['javac'],
    }
    JAVADOC = {
        'darwin': ['javadoc'],
        'ipod': [],
        'linux2': ['/usr/lib/jvm/java-8-openjdk-amd64/bin/javadoc'], # jdk安装路径
        'sunos5': ['javadoc'],
        'win32': ['%(win32)s/bin/javadoc.exe' %(JDK)],
        'mingw32': ['%(mingw32)s/bin/javadoc.exe' %(JDK)],
        'freebsd7': ['javadoc'],
    }
    

    保存并关闭后执行:

    sudo /home/username/anaconda3/envs/venv27/bin/python setup.py build
    sudo /home/username/anaconda3/envs/venv27/bin/python setup.py install
    popd
    vi Makefile
    

    添加如下代码,注意python的位置!

    # Linux  (Ubuntu 16.04, Python 2.7, JDK 8u121, no setuptools)
    PREFIX_PYTHON=/home/t-jin/anaconda3/envs/venv27
    ANT=JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 /usr/bin/ant
    PYTHON=$(PREFIX_PYTHON)/bin/python
    JCC=$(PYTHON) -m jcc --shared
    NUM_FILES=8
    

    修改pylucene-6.2.0/lucene-java-6.2.0/lucene/expressions/lib目录下文件的simlink(重要)

    默认如下:

    antlr4-runtime-4.5.1-1.jar -> /Users/vajda/.ivy2/cache/org.antlr/antlr4-runtime/jars/antlr4-runtime-4.5.1-1.jar
    asm-5.1.jar -> /Users/vajda/.ivy2/cache/org.ow2.asm/asm/jars/asm-5.1.jar
    asm-commons-5.1.jar -> /Users/vajda/.ivy2/cache/org.ow2.asm/asm-commons/jars/asm-commons-5.1.jar
    

    修改:

    ln -snf /home/username/.ivy2/cache/org.antlr/antlr4-runtime/jars/antlr4-runtime-4.5.1-1.jar antlr4-runtime-4.5.1-1.jar
    ln -snf /home/username/.ivy2/cache/org.antlr/antlr4-runtime/jars/asm-5.1.jar asm-5.1.jar
    ln -snf /home/username/.ivy2/cache/org.antlr/antlr4-runtime/jars/asm-commons-5.1.jar asm-commons-5.1.jar
    

    保存并关闭后执行:

    make
    make test
    sudo make install
    

    补充

    1. 最好安装 Ivy

    官网下载 binary-with-dependencies 版本,解压后执行如下命令即可

    sudo cp ivy-2.5.0-rc1.jar /usr/share/ant/lib/ # ant的安装路径
    

    2. SmartChineseAnalyzer报错

    Pylucene不能导入SmartChineseAnalyzer的解决办法

    在Makefile相应位置添加

    --exclude org.apache.lucene.analysis.cn.smart.AnalyzerProfile\
    

    参考:
    https://blog.csdn.net/thuyx/article/details/69284170

    相关文章

      网友评论

          本文标题:PyLucene Setup

          本文链接:https://www.haomeiwen.com/subject/ikgfpftx.html