ninia / jep

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

import numpy exception in sharedInterpreter using jep #536

Closed Dynasty-develop closed 1 month ago

Dynasty-develop commented 1 month ago

Problem 1.jep.JepException: <class 'ImportError'>: Error importing numpy: you should not try to import numpy from its source directory; please exit the numpy source tree, and relaunch your python interpreter from there. 2.jep.JepException: <class 'ImportError'>: /usr/local/python3/lib/python3.10/lib-dynload/_posixsubprocess.cpython-310-x86_64-linux-gnu.so: undefined symbol: PyTuple_Type

Environment :

Centos 7 Python 3.10.14 Java Distribution and Version: jdk 8 Jep Version: jep-4.2.0 Python packages used : numpy, cv2, onnxruntime, torch, skimage

I suceed to install JEP/Java/python environment. My project is working fine in my local Windows computer. When I deploy the project to Centos 7 and use jep to call python script, I am getting "Import Error". But I directly run the python script, its alse work abnormally. I am completely confused and dont know how to solve this trouble.

Troubleshooting: sys.path from jep: [/usr/local/python3/lib/python310.zip, /usr/local/python3/lib/python3.10, /usr/local/python3/lib/python3.10/lib-dynload, /usr/local/python3/lib/python3.10/site-packages, /home/xxx/xxx/xxx/xxx]

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"

Please help! thank you!

Dynasty-develop commented 1 month ago

The ultimate reason is that it was not compiled correctly the Python source code package, it caused to lack the libpython3.10.so file and jep can`t work normally. So the solved method is recompile Python source code package with the command "./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl --enable-shared". After do this, anything work fine.