javapythonjpype

jpype.startjvm exits without giving any error message


I am trying to use Python MPXJ to analyze info from mpp file. In my Windows 10 machine, I have a 32bit Python 3.8.0 installed and JPYPE prepared by pip install jpype1. I am also installing JRE 32bit in C:\Program Files (x86)\Java\jre1.8.0_301.

However, The following script simply fails

import jpype

print(jpype.getDefaultJVMPath())
jpype.startJVM()
print("JVM successfully started")
jpype.shutdownJVM()

It shows the default path as C:\Program Files (x86)\Java\jre1.8.0_301\bin\client\jvm.dll, However the next print line is not executed, nor do startJVM give any error output. The execution result is as the following

> python testjvm.py
C:\Program Files (x86)\Java\jre1.8.0_301\bin\client\jvm.dll

So startJVM get executed, but exit without giving anything.

Is there a way to further debugging what might be the problem?


I am doing further debugging with ipython per John's suggestion. It goes to c:\python38\lib\site-packages\jpype\_core.py(226) with the following context

> c:\python38\lib\site-packages\jpype\_core.py(225)startJVM()
    223                         % (','.join([str(i) for i in kwargs])))
    224
3-> 225     try:
    226         _jpype.startup(jvmpath, tuple(args),
    227                        ignoreUnrecognized, convertStrings, interrupt)

ipdb> jvmpath
'C:\\Program Files (x86)\\Java\\jre1.8.0_301\\bin\\client\\jvm.dll'
ipdb> args
args = []
kwargs = {}
ipdb> tuple(args)
()
ipdb> ignoreUnrecognized
False
ipdb> convertStrings
False
ipdb> interrupt
False

Then no matter I press s or n on _jpype.startup, the ipython exit without any prompt


Solution

  • Thanks for John Hennig's comment, which point out the root cause may be x86 and x64 incompatibility issue.

    I do some further debugging per JVM startup debugging. Basically it uses Dumpbin utility which come togehter with Visual Studio to check every component to see if it is x86 or x64. If any of them is incompatible, the jvm start will crash.

    Turn out the python.exe and jvm.dll in my machine are all x86. However, when using where to locate the dependencies

        KERNEL32.dll
        USER32.dll
        ADVAPI32.dll
        WSOCK32.dll
        WINMM.dll
        VERSION.dll
        PSAPI.DLL
        VCRUNTIME140.dll
        api-ms-win-crt-stdio-l1-1-0.dll
        api-ms-win-crt-string-l1-1-0.dll
        api-ms-win-crt-runtime-l1-1-0.dll
        api-ms-win-crt-convert-l1-1-0.dll
        api-ms-win-crt-environment-l1-1-0.dll
        api-ms-win-crt-utility-l1-1-0.dll
        api-ms-win-crt-math-l1-1-0.dll
        api-ms-win-crt-filesystem-l1-1-0.dll
        api-ms-win-crt-time-l1-1-0.dll
        api-ms-win-crt-heap-l1-1-0.dll
    

    It turns out the first dll KERNEL32.dll is located in c:\Windows\System32, and it is x64. The same is for other dlls. Since they are system default dlls in x64 windows, it will be very tricky to replace them with x86 ones. So it is not possible to use python x86 version with JPype in x64 windows.

    The solution is straight forward, changing python/java to x64 version fixes the issue.