java - 如何在 jep 中使用其他 python 模块?
问题描述
我在 IntelliJ-IDEA 中设置了一个 jep 项目,并且在运行代码时不断收到此错误:
Exception in thread "main" jep.JepException: <class 'ModuleNotFoundError'>: No module named 'spacy'
at src/main/python\nlq_wrapper.<module>(nlq_wrapper.py:2)
at <string>.<module>(<string>:1)
at jep.Jep.exec(Native Method)
at jep.Jep.exec(Jep.java:478)
at com.siemens.nlqwrapper.NLQWrapper.load(NLQWrapper.java:37)
at com.siemens.nlqwrapper.Main.main(Main.java:9)
即使 spacy 包含在我的解释器 SDK 包中。
另一个奇怪的地方是 IntelliJ-IDEA 中的 Python 终端可以找到并使用 spacy。
但是当我尝试从终端或系统的 CLI 运行程序时,它找不到模块并且我得到同样的错误。
我需要为 jep 做一些额外的配置才能使用其他 python 模块吗?还是 jep 与其他模块不兼容?
解决方案
我通过您在 JEP 解释器之前调用的这段代码修复了它:
PyConfig pyConfig = new PyConfig();
pyConfig.setPythonHome("/home/user/[NEW_PYTHON_HOME]/");
try {
MainInterpreter.setInitParams(pyConfig);
} catch (JepException e) {
e.printStackTrace();
}
阿里
推荐阅读
- asp.net-core - Swagger 版本控制不起作用。它显示所有端点,尽管选择了 API 版本
- sql - 获取列中最常见的值
- java - 如何在生产者之前启动kafka消费者
- flutter - 如何枚举注册用户列表
- firebase - 使用 Flutter ChangeNotifierProvider 进行身份验证
- c - 将大小为 l*b 的面包切成相同的小块,使每一块都是具有最大可能边长的正方形
- ruby-on-rails - 在 Spree Orders 表中添加回形针附件,
- ipu - PopART 中的损失张量被从图中剪除
- shopify - 使用变体产品添加 shopify 附加费
- vue.js - 如何使用依赖于数据、道具或计算中的字段的方法为 Vue mixin 实现干净的接口