ninia / jep

Embed Python in Java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JEP : jep.JepException : Error importing numpy

roopannava opened this issue · comments

Problem
jep.JepException: <class 'ImportError'>: Error importing numpy: you should not try to import numpy from
2024-03-29 14:13:17,426 ERROR [stderr] (Timer-6) its source directory; please exit the numpy source tree, and relaunch
.

Environment :

  • Centos 7.9
  • Python 3.12
  • Java Distribution and Version: jdk 11
  • Jep Version: jep-4.2.0
  • Python packages used : numpy, pandas, patsy , joblib

I am setting up JEP/Java and accessing a python functions which has numpy, pandas,patsy and joblib.
My project is working fine in my local Mac environment. When I push the code to Centos 7.9, I am getting "Import Error".
I have read the articles https://stackoverflow.com/questions/14570011/explain-why-numpy-should-not-be-imported-from-source-directory but I couldn't resolve the issue when I move the python packages to another path.

Troubleshooting:
sys.path : I am logging out this when my java method call the python function:
Value: ['/usr/local/lib/python312.zip', '/usr/local/lib/python3.12', '/usr/local/lib/python3.12/lib-dynload', '/usr/local/lib/python3.12/site-packages', '/mypython/modlel'

JEP:

(jep is installed under the site-packages)

Observations:
I can see the interpreters is initialized but when function call goes, I am getting the "Import Error"

What I am doing wrong here?
I have installed all the packages with pip3.12
It is working fine in Mac

Please help!
thank you

    jepPath = /my/site-packages/jep/libjep.so
    MainInterpreter.setJepLibraryPath(jepPath);
    jep.JepConfig jepConf = new JepConfig();
    jepConf.addIncludePaths("/my/pythonmodel");
    jepConf.addIncludePaths("/my/site-packages");
    SharedInterpreter.setConfig(jepConf);

I figured out the root cause. I have to place the python module file under the …./site-packages.