ninia / jep

Embed Python in Java
Other
1.31k stars 149 forks source link

JEP : jep.JepException : Error importing numpy #525

Open roopannava opened 6 months ago

roopannava commented 6 months ago

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 :

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)
            <Property name="**PYTHON_MODEL_PATH**"   value="/mypython/model"/>

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

roopannava commented 6 months ago
    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);
roopannava commented 6 months ago

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

Dynasty-develop commented 4 months ago

I meet same trouble. But I don`t understand your solution. Can you please interpreter more detail?