ninia / jep

Embed Python in Java
Other
1.27k stars 146 forks source link

About LD_LIBRARY_PATH and LD_PRELOAD #534

Open qmj123 opened 1 month ago

qmj123 commented 1 month ago

Describe the problem How to solve the following problems without setting the LD_PRELOAD parameter and How to set environment variables in Java's Jep. jep.JepException: <class 'ImportError'>: /xxx/python/lib/python3.10/lib-dynload/_posixsubprocess.cpython-310-x86_64-linux-gnu.so: undefined symbol: PyTuple_Type

Environment (please complete the following information):

Dynasty-develop commented 1 month ago

I have same problem. I can`t solve this for a week.

Dufgui commented 2 weeks ago

me too

bsteffensmeier commented 2 weeks ago

In some cases this can be solved by setting PYTHONHOME or using PyConfig.setPythonHome(). In some cases LD_PRELOAD may be required when other native python libraries depend on libpython but do not declare that dependency as part of their library. This is unfortunately a common way of building native python extensions so they can be used with a statically linked python executable. There is nothing jep can do to solve this since it is a problem with libraries that are not part of jep.

For example in the case of _posixsubprocess.cpython-310-x86_64-linux-gnu.so, it is looking for a symbol that is defined in libpython. If _posixsubprocess.cpython-310-x86_64-linux-gnu.so declares a dependency on libpython then the symbol would be available to it. Since the symbol is not available I can only assume it did not declare a dependency. You can check the dependencies on linux by running ldd /xxx/python/lib/python3.10/lib-dynload/_posixsubprocess.cpython-310-x86_64-linux-gnu.so The correct solution is for _posixsubprocess.cpython-310-x86_64-linux-gnu.so to declare a dependency on libpython.