ninia / jep

Embed Python in Java
Other
1.3k stars 147 forks source link

I have already export the LD_LIBRARY_PATH in linux, but still can't import jep in my JAVA #429

Closed onegoldfish closed 8 months ago

onegoldfish commented 1 year ago

Describe the problem I have already export the LD_LIBRARY_PATH in linux, but still can't import jep in my JAVA

ls /usr/local/python3/lib/python3.7/site-packages/jep console.py libjep.so init.py pycache java_import_hook.py redirect_streams.py jdbc.py shared_modules_hook.py jep-4.0.3.jar version.py jep.cpython-37m-x86_64-linux-gnu.so

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/python3/lib/python3.7/site-packages/jep

echo $LD_LIBRARY_PATH /usr/local/python3/lib/python3.7/site-packages/jep

Did I do something wrong? What else can I do to make java find jep?

jdk1.8 and python 3.7, in centos 7

my JAVA code:

import jep.*;
public class hello {
    public static void main(String[] args) {
        try (Interpreter interp = new SharedInterpreter()) {
            interp.exec("from java.lang import System");
            interp.exec("s = 'Hello World'");
            interp.exec("System.out.println(s)");
            interp.exec("print(s)");
            interp.exec("print(s[1:-1])");
        }
        System.out.println("finish");
    }
}
bsteffensmeier commented 1 year ago

You may need to update your environment to help your system find libpython, which libjep needs to run. You should be able to add the directory containing libpython to you LD_LIBRARY_PATH or set LD_PRELOAD to the full path of libpython.

There should be a jep script in /usr/local/python3/bin which contains an example of the env vars to set for jep to load.

onegoldfish commented 1 year ago

I'm sorry I didn't understand how to update my environment. My jep is installed in /usr/local/python3/lib/python3.7/site-packages/jep, and there is a jep script in /usr/local/python3/bin. What the LD_LIBRARY_PATH should be?

My libpython3.7m.so.1.0 is in/usr/lib64, which is already included in the

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/python3/lib:/usr/local/python3/bin

java.library.path:-----------
:/usr/local/python3/lib:/usr/local/python3/bin:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
bsteffensmeier commented 1 year ago

if you open the jep script it is a small shell script and it has an example of settings for LD_LIBRARY_PATH, LD_PRELOAD and java.library.path for a java application using jep. The jep script was created during the jep install using the specific settings for your install and the settings it uses are usually correct. You can check if these ssetting are correct by running the script, it should give you a python prompt.

I was expecting your libpython to exist somewhere under /usr/local/python3, usually it exists in the same directory structure as your site-packages and python bin but I am not familiar enough with your system to know for sure if you have the correct libpython.

If that is the correct libpython then your settings look correct and I do not know of any reason the jep library would not load. Are there any more speciifc details in the error message you are seeing, often if there is an issue with finding certain dependencies it will be mentioned in the error message.

onegoldfish commented 1 year ago

Thank you for your patience. Unfortunately, I still haven't found the problem. I used to use pipto install. Now I'm going to use python setup.py build to install. But when I execute python setup.py build, I got message as follows:

numpy include found at /usr/local/python3/lib/python3.7/site-packages/numpy/core/include
running build
running setup_java
running build_java
running build_jar
running build_py
running build_ext
running build_scripts
/usr/local/python3/lib/python3.7/site-packages/setuptools/command/install.py:37: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
  setuptools.SetuptoolsDeprecationWarning,

Maybe it's about the pip version?

pip -V
pip 22.2.2 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)

I would be very grateful if you could help me. Thank you for your time and effort!

onegoldfish commented 1 year ago

I have solved the pip problem! Thank you for your previous reply. If you know the cause of error python setup.py build, please tell me, thank you!

bsteffensmeier commented 8 months ago

Closing due to inactivity.