jpype.startjvm 退出而不给出任何错误信息

jpype.startjvm exits without giving any error message

我正在尝试使用 Python MPXJ 来分析来自 mpp 文件的信息。在我的 Windows 10 机器上,我安装了 32 位的 Python 3.8.0 和 JPYPEpip install jpype1 准备的。我也在 C:\Program Files (x86)\Java\jre1.8.0_301.

安装 JRE 32bit

然而,下面的脚本完全失败了

import jpype

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

它显​​示默认路径为C:\Program Files (x86)\Java\jre1.8.0_301\bin\client\jvm.dll,但是下一行打印没有执行,也没有startJVM给出任何错误输出。执行结果如下

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

所以startJVM被执行了,但是没有给出任何东西就退出了。

有没有办法进一步调试可能是什么问题?


我正在根据 John 的建议使用 ipython 进行进一步调试。它转到 c:\python38\lib\site-packages\jpype\_core.py(226) 具有以下上下文

> 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

然后无论我在_jpype.startup上按sn,ipython都没有任何提示退出

感谢 John Hennig 的评论,指出根本原因可能是 x86 和 x64 不兼容问题。

我根据 JVM startup debugging. Basically it uses Dumpbin 实用程序与 Visual Studio 一起进行了一些进一步的调试,以检查每个组件以查看它是 x86 还是 x64。如果其中任何一个不兼容,jvm 启动将崩溃。

原来我机器里的python.exejvm.dll都是x86的。但是,当使用 where 定位依赖项时

    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

原来第一个dll KERNEL32.dll 位于c:\Windows\System32,而且是x64。其他dll也是如此。由于它们是 x64 windows 中的系统默认 dll,因此用 x86 替换它们将非常棘手。所以不可能在 x64 windows.

中将 python x86 版本与 JPype 一起使用

解决方案很简单,将 python/java 更改为 x64 版本即可解决问题。