python全文检索库pylucene在windows下安装方法,太费劲了,好多地方报错

一,下载pylucene安装包
下载地址:https://mirrors.tuna.tsinghua.edu.cn/apache/lucene/pylucene/pylucene-9.7.0-src.tar.gz
官网根本没网速
二,解压
D:\install\pro\python\pylucene-9.7.0\jcc
在命令行下进入 jcc 文件夹,输入 python setup.py build ,如果没有错误信息,继续输入 python setup.py install 安装 JCC 。重启电脑
教程:https://www.cnblogs.com/hanhaotian/p/13361691.html
三、Can’t determine where the Java JDK has been installed on this machine.

Please set the environment variable JCC_JDK to that location before
running setup.py.
下载地址:https://download.java.net/java/GA/jdk21.0.1/415e3f918a1f4062a0074a2794853d0d/12/GPL/openjdk-21.0.1_windows-x64_bin.zip
JCC_JDK D:\ide\jdk-21.0.1
四、出现:Microsoft Visual C++ 14.0 is required 的解决方案
下载地址:
生成工具
https://download.visualstudio.microsoft.com/download/pr/ebbb3a8f-0b8f-4c9d-ac08-5e244e84b4fe/d4e08524cb0e5bd061a24f507928d1cfb91dce192c5e12ed964b8343fc4cdedd/vs_BuildTools.exe
或者完整开发工具
https://c2rsetup.officeapps.live.com/c2r/downloadVS.aspx?sku=community&channel=Release&version=VS2022&source=VSLandingPage&cid=2030:5f0f8ce6355245eda6fbb9ba37b6d7ee
C:\Program Files (x86)\Microsoft Visual Studio\Installer\setup.exe

五、很多解决方案都是错的!我是安装以下方法编译成功:
https://www.cnblogs.com/ToDoToTry/p/11970611.html
Windows平台上,pip install fastFM scrapy等工具的时候,经常出现 error Microsoft Visual C++ 14.0 is required 的错误,

原因是部分python包是使用c或者c++编写的,因此在安装的时候需要使用 c++生成工具集。

解决方案有两个:
到 https://www.lfd.uci.edu/~gohlke/pythonlibs 下载编译好的包

安装vc++ 14 build tools :
安装 visual studio 最新版, 选择 vc++ build tools 和 windows sdk 10
最关键: pip install --upgrade setuptools 才能自动发现 vc++ compilers ( Before do anything, install or upgrade the Setuptools Python package. It contain compatibility improvements and add automatic use of compilers:)
六、在命令行下进入 jcc 文件夹,输入 python setup.py build ,如果没有错误信息,继续输入 python setup.py install 安装
Finished processing dependencies for JCC==3.13

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PyLucene 是一个 Python 的 Lucene ,它提供了 Python 与 Java 编写的 Lucene API 的绑定,可以用于创建和操作 Lucene 索引,执行全文搜索和文本分析等任务。下面是 PyLucene安装和使用方法: 1. 安装 Java PyLucene 是一个 Python ,但它依赖于 Java 的 Lucene 。因此,在安装 PyLucene 之前,需要先安装 Java。 2. 安装 JCC JCC 是一个 Java 原生代码编译器,用于为 Python 和 Java 之间的代码绑定生成 JNI 接口。PyLucene 使用 JCC 进行 Python 与 Java 的交互。因此,需要先安装 JCC。 可以使用以下命令安装 JCC: ``` pip install https://github.com/elasticdog/jcc/archive/master.zip ``` 3. 下载 PyLucene 可以从 Apache Lucene 的官方网站下载 PyLucene 的源代码,下载地址为: http://www.apache.org/dyn/closer.lua/lucene/pylucene/ 选择与您使用的 Python 版本和操作系统相应的版本进行下载。 4. 编译 PyLucene 在下载 PyLucene 的源代码后,需要对其进行编译。在编译 PyLucene 之前,需要确保已经安装了 setuptools、numpy 和 Cython。 在命令行中进入 PyLucene 的源代码目录,运行以下命令进行编译: ``` make make install ``` 上述命令将会编译 PyLucene 并将其安装Python 的 site-packages 目录下。 5. 使用 PyLucene 安装完成 PyLucene 后,就可以使用其提供的 API 进行全文搜索和文本分析等任务了。下面是一个简单的示例: ```python from lucene import * # 初始化 Java 虚拟机 vm_env = getVMEnv() # 创建索引 index_dir = SimpleFSDirectory(Paths.get('index')) analyzer = StandardAnalyzer() index_writer = IndexWriter(index_dir, IndexWriterConfig(analyzer)) doc = Document() doc.add(StringField('title', 'Hello World', Field.Store.YES)) index_writer.addDocument(doc) index_writer.commit() index_writer.close() # 执行搜索 index_reader = DirectoryReader.open(index_dir) index_searcher = IndexSearcher(index_reader) query_parser = QueryParser('title', analyzer) query = query_parser.parse('Hello') hits = index_searcher.search(query, 10).scoreDocs for hit in hits: doc = index_searcher.doc(hit.doc) print(doc.get('title')) index_reader.close() ``` 上述示例程序首先初始化了 Java 虚拟机,然后创建了一个包含一个文档的索引,并将其保存到磁盘上。接着,它执行了一个基于查询的搜索操作,并输出了搜索结果。 更多 PyLucene 的用法可以参考其官方文档: https://lucene.apache.org/pylucene/api.html

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值