ninia / jep

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

jep(4.0.3) import numpy(1.23.1) failed #420

Closed Adamatoma closed 2 years ago

Adamatoma commented 2 years ago

Describe the problem import numpy failed when i got jep(4.0.3) and numpy(1.23.1) in python (3.10.5) installed cmd: python3 -m pip install numpy python3 -m pip install jep then go to jep run: import numpy will get follow issue:

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:

  * The Python version is: Python3.10 from "/Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home/bin/java"
  * The NumPy version is: "1.23.1"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: dlopen(/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so, 2): no suitable image found.  Did find:
    /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so: mach-o, but wrong architecture
    /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so: mach-o, but wrong architecture

Search for existing solutions I look through some relevant topic on Google Jep Project Forum but haven't solve my problem. https://groups.google.com/g/jep-project/c/WEIxatC1Kfs/m/IUE7lVzqAgAJ https://groups.google.com/g/jep-project/c/GX-Oq2ZbXeE/m/zm4DeKiKBwAJ

Environment (please complete the following information):

Logs Please attach the complete console output of the build.

Additional context python 3.6.5 works fine, so i guess it might be some compatible problem.

bsteffensmeier commented 2 years ago

You need to verify that all the related components are built for the same architecture. The error suggests that your Java, Python, and Jep library are built for one architecture while your numpy library is built for a different, incompatible architecture. I suspect you are running an arm based mac with an x86-64 version of Java. Depending on whether you want to be running the program with arm or x86-64 you may need to install an arm version of Java or an x86-64 version of numpy. Whichever architecture you choose you will also need compatible versions of python and jep.

Adamatoma commented 2 years ago

Hi Ben, thanks for your reply, which is really helpful! I guess my problem would be incompatible of x86-64 Java with ARM numpy. That explains why python 3.6.5 works fine while 3.10.5 fails. python 3.10.5 gives me a "universal2 installer", which is a python version for ARM i guess.
python 3.6.5 is a x86-64 version image image Are these correct?

bsteffensmeier commented 2 years ago

I do not have a mac and I am not an expert on mac. It is my understanding that the universal2 installer is compatible with both arm64 and x86_64 macs, each executable and binary contains the compiled code for both and the correct version is selected when you use it. Numpy is distributing separate wheels for x86_64 and arm64.

When you run python or pip from the command line I assume the OS will pick the arm64 version over x86_64 since arm64 is more nativer. If that is the case then it makes sense for pip to choose the arm64 version of numpy.

When you include python from a java application, the x86_64 version of python will be used because that is the only version compatible with your x86_64 version of java.

If this is a correct analysis then you need to either get an arm64 version of java or you need to force pip to install the x86_64 version of numpy. I believe if you manually download the x86_64 wheel for numpy you will be able to install that wheel locally using pip.

Adamatoma commented 2 years ago

Thanks Ben, Problem solved, works well! Cheers!