首页 > 解决方案 > 如何在 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 与其他模块不兼容?

编辑
为了进一步说明,这里是 Java 和 Python 的运行配置。

Java 运行配置: Python 运行配置:

标签: javapythonintellij-ideajep

解决方案


我通过您在 JEP 解释器之前调用的这段代码修复了它:

 PyConfig pyConfig = new PyConfig();
  pyConfig.setPythonHome("/home/user/[NEW_PYTHON_HOME]/");
  try {
    MainInterpreter.setInitParams(pyConfig);
  } catch (JepException e) {
       e.printStackTrace();
  }

阿里


推荐阅读