Jep intialization failed in Mac OSX

瀏覽次數:298 次
跳到第一則未讀訊息

Aravind Siripireddy

未讀,
2019年9月10日 上午8:25:562019/9/10
收件者:Jep Project
Hello Team,

I'm trying run the below code snippet to test my jep environment but seeing the error as follows


public static void main(String[] args) throws JepException {

     MainInterpreter.setJepLibraryPath("/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/jep/libjep.jnilib");

     

     Jep jep = new Jep();

     // evaluates and returns the results

     Integer y = (Integer) jep.getValue("2 + 4");

   

      System.out.println( y);

   

      jep.close();

}


Error:

--------

Exception in thread "main" java.lang.UnsatisfiedLinkError: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/jep/libjep.jnilib: dlopen(/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/jep/libjep.jnilib, 1): Library not loaded: @rpath/libpython3.7m.dylib

  Referenced from: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/jep/libjep.jnilib

  Reason: image not found

at java.base/java.lang.ClassLoader$NativeLibrary.load0(Native Method)

at java.base/java.lang.ClassLoader$NativeLibrary.load(ClassLoader.java:2430)

at java.base/java.lang.ClassLoader$NativeLibrary.loadLibrary(ClassLoader.java:2487)

at java.base/java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2684)

at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2617)

at java.base/java.lang.Runtime.load0(Runtime.java:767)

at java.base/java.lang.System.load(System.java:1831)

at jep.MainInterpreter.initialize(MainInterpreter.java:125)

at jep.MainInterpreter.getMainInterpreter(MainInterpreter.java:101)

at jep.Jep.<init>(Jep.java:256)

at jep.Jep.<init>(Jep.java:251)

at jep.Jep.<init>(Jep.java:149)

at com.altair.ba.executionengine.BAPythonEngine.main(BAPythonEngine.java:12)


MyEnvironment:
------------------------
OSX : mojave 10.14.6
Python : 3.7.4 (v3.7.4:e09359112e, Jul  8 2019, 14:54:52) 
Java: Java11

Installed Jep 3.9.0 using 'Pip' and added jep.3.9.0.jar in to classpath.

I have tried setting below env variables in ~/.bash_profiles, but is of no help


export NRN_PYLIB=<PATH_TO>/libpython3.7m.dylib

export LD_LIBRARY_PATH= <PATH_TO>/libpython3.7m.dylib


Please let me know whats going wrong.


Thanks,

Aravind




Nathan Jensen

未讀,
2019年9月10日 上午11:34:202019/9/10
收件者:Jep Project
Did you try setting PYTHONHOME?  See this ticket's history: https://github.com/ninia/jep/issues/113  Please let us know if that works or not, I'm curious if PYTHONHOME is required or not since you called MainInterpreter.setJepLibraryPath(String).

--
You received this message because you are subscribed to the Google Groups "Jep Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jep-project...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jep-project/54680ee0-de58-4bb2-87fc-8a372e590eab%40googlegroups.com.

Ben Steffensmeier

未讀,
2019年9月10日 上午11:49:012019/9/10
收件者:Jep Project
Try using System.load() to load libpython before you use jep.

Ashish Rajput

未讀,
2019年9月19日 凌晨2:53:402019/9/19
收件者:Jep Project
Tried 

System.load("/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/config-3.7m-darwin/libpython3.7m.dylib");

but that also not working.

Ben Steffensmeier

未讀,
2019年9月19日 晚上10:46:192019/9/19
收件者:Jep Project
That looks right to me. Did you do both System.load("/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/config-3.7m-darwin/libpython3.7m.dylib") and MainInterpreter.setJepLibraryPath("/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/jep/libjep.jnilib")? libjep depends on libpython so you need to do both and you must load libpython before libjep. Does it produce the same Library not loaded message as before?

My experience is all on linux but I have specifically tested to ensure that when the system cannot resolve libpython then System.load can be used to load libpython which enables libjep to load. I would've expected the same to work on OSX but I don't know for sure.

You could try setting the PYTHONHOME as Nate suggested, however in this case do not call MainInterpreter.setJepLibraryPath() since that call will cause PYTHONHOME to be ignored. I think the correct value for PYTHONHOME for your environment would be "/Library/Frameworks/Python.framework/Versions/3.7". If you set this variable in your ~/.bash_profile then make sure to start a fresh terminal so the settings take effect. I am not very optimistic about this approach because internally the LibraryLocator will be using System.load() to load libpython and then libjep which matches what you are doing already but perhaps having them both loaded from within the same class will make some difference in the way the JVM handles them.

You mention setting LD_LIBRARY_PATH but I know OSX also looks in DYLD_LIBRARY_PATH and DYLD_FALLBACK_LIBRARY_PATH so you might try setting one or both of those. I think the correct value for these for your environment would be "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/config-3.7m-darwin/". You could also try setting LD_PRELOAD to "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/config-3.7m-darwin/libpython3.7m.dylib" which should cause libpython3.7m.dylib to load in your process automatically. While I know some of these settings have worked in the past I don't know if any of them work any more since OSX has added System Integrity Protection which changes the behavior of all those settings. Another option is to disable System Integrity Protection but I do not know enough about OSX to tell you if that is at all reasonable.

I am a bit concerned by the presence of @rpath in your error message. I am only a little familiar with rpath and only in linux but I do not think it is usually used in libjep. You may want to try configuring the rpath within libjep so that it includes the path to libpython. I think the correct command to do this would be: "install_name_tool -add_rpath /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/config-3.7m-darwin/ /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/jep/libjep.jnilib". It might be slightly more portable to use a relative path to libpython, which would be "install_name_tool -add_rpath ../../config-3.7m-darwin/ /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/jep/libjep.jnilib". I don't have a mac to test on so I can't confirm either but from what I have read that should solve this.

As an alternative to manually setting the rpath, you can also set the rpath during the build. I don't know how to change the settings with pip but if you have the jep source the command would be "./setup.py build_java build_ext --rpath=/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/config-3.7m-darwin/ install". I've considered trying to automatically set the rpath during the build, however it reduces the portability of libjep especially for people using anaconda.

Please let us know if any of that helps you. We seem to have been having more problems with OSX since System Integrity Protection was added and I was hoping some of the new things we added to LibraryLocator in the last few releases would make things easier. Any information you can give on what works on your system will help us understand how it works better so we can try to come up with some way to simplify this.

Akash Wadagire

未讀,
2023年9月11日 上午8:23:372023/9/11
收件者:Jep Project
Hi Good Evening 
I am Akash , I am trying to call the python from the Java (in the Spring boot ) can you guide me how to set up the JEP in the Spring boot or please share  me the link or notes .
thank you 
回覆所有人
回覆作者
轉寄
0 則新訊息