Closed Marmot01 closed 2 months ago
It looks like maybe numpy wasn't built correctly. Does it import ok in a regular Python interpreter?
@ndjensen I got the same problem. It works when I execute python3 test.py but fail in jep
` ERROR ~ jep.JepException: <class 'ImportError'>: Unable to import required dependencies: numpy:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for many reasons, often due to issues with your setup or how NumPy was installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
and make sure that they are the versions you expect. Please carefully study the documentation linked above for further help.
Original error was: /home/tops/lib/python3.7/site-packages/numpy/core/_multiarray_umath.cpython-37m-x86_64-linux-gnu.so: undefined symbol: PyExc_ImportError`
Typically an undefined symbol is caused because a library(in this case _multiarray_umath.cpython-37m-x86_64-linux-gnu.so), does not declare a dependency on libpython so it does not have access to the necessary symbols defined in libpython. In a python process these symbols are loaded globally and available to all libraries but in a java process they are not. Jep contains code that attempts to load these symbols globally but that must not be working in your environment.The simplest solution in this case is to set the env var LD_PRELOAD to the absolute path of libpython3.7.so
Describe the problem package day;
import jep.JepConfig; import jep.JepException; import jep.LibraryLocator; import jep.MainInterpreter; import jep.NamingConventionClassEnquirer; import jep.PyConfig; import jep.SharedInterpreter;
public class Demo01 { public static void main(String[] args) throws JepException { PyConfig pyConfig = new PyConfig(); String pyHome = "xxx"; pyConfig.setPythonHome(pyHome); LibraryLocator.findJepLibrary(pyConfig); MainInterpreter.setInitParams(pyConfig); NamingConventionClassEnquirer enquirer = new NamingConventionClassEnquirer(true); enquirer.addTopLevelPackageName("command"); JepConfig jepConfig = new JepConfig(); jepConfig.setClassEnquirer(enquirer); jepConfig.setRedirectOutputStreams(true); SharedInterpreter.setConfig(jepConfig); SharedInterpreter interpreter = new SharedInterpreter(); interpreter.exec("import numpy"); interpreter.close();
}
Environment (please complete the following information):
Additional context when I import numpy ,original error was: /xxx/site-packages/numpy/core/_multiarray_umath.cpython-36m-x86_64-linux-gnu.so: undefined symbol: PyExc_ImportError.