jpype-project / jpype

JPype is cross language bridge to allow Python programs full access to Java class libraries.
http://www.jpype.org
Apache License 2.0
1.12k stars 181 forks source link

JVM DLL not found in the directory where it actually is #777

Open dwolffenbuttel opened 4 years ago

dwolffenbuttel commented 4 years ago

Hello!

I'm running into a problem with JPype and hope anyone can help me. I'm trying to run NetLogo in python using PyNetLogo, which runs JPype for setting up JVM. On my own pc: win10 64bit with 64 bit Python, NetLogo and Java everything works fine. Since my pc is not powerful enough for running my simulations in a decent amount of time, I'm trying to run them on a VM with win10 on a server. I installed all the packages and software as I did on my own computer, however, now I run into the following error whilst running startJVM:

OSError: [WinError 126] JVM DLL not found: C:\Program Files\Java\jre1.8.0_241\bin\server\jvm.dll

However, where Jpype is not able to find the dll, is actually where it is. I found online that I needed to add JAVA_HOME to my environment variables, and add jre\bin to PATH. I also tried specifying the path manually using r"filepath\folder" and with double \ and with normal slashes as opted in a few discussions. All of these solutions did not resolve the issue unfortunately and now I have ran out of ideas. Any suggestions?

Hopefully someone can help out with this problem!

Thanks in advance

Thrameos commented 4 years ago

Try the instructions in the directory project/debug/windows from the master branch. A few people run into this issue, but I have not had a good explanation of what is going wrong. As far as I can tell it is not a function of JPype but rather library problem with the JVM on a windows 10 install. I have run window 10 install without issue.

Alternatively you may want to try WSL2 on window10. That configuration works well for me.

dwolffenbuttel commented 4 years ago

Thanks for the fast response!

I tried the instructions. Found that the architecture for python and jvm.dll is correct. I looked up the dependencies and found:
KERNEL32.dll USER32.dll ADVAPI32.dll WSOCK32.dll WINMM.dll VERSION.dll PSAPI.DLL MSVCR100.dll Of these only the last one was present in bin. The others I found in system32, however copying them to jdk/bin did not solve the problem. I checked the architecture for all these .dll's, no deficiencies there either.

I tried testing the JVM, however, I did not quite understand what to do. I ran CL.EXE test.JVM.cpp in the native tools command prompt, but got this error: c1xx: fatal error C1083: Cannot open source file: 'testJVM.cpp': No such file or directory.

I am not a software engineer, so some of this is magic to me. Any ideas for what I can try next to solve this? I just want to get Jpype up and running because I need it for PyNetlogo to work.

Thrameos commented 4 years ago

The list of dependencies does not match the one in the readme file. So I checked that version.

Microsoft (R) COFF/PE Dumper Version 14.00.24245.0
Copyright (C) Microsoft Corporation.  All rights reserved.

Dump of file C:\Program Files\Java\jdk1.8.0_242\jre\bin\server\jvm.dll

File Type: DLL

  Image has the following dependencies:

    KERNEL32.dll
    USER32.dll
    ADVAPI32.dll
    WSOCK32.dll
    WINMM.dll
    VERSION.dll
    PSAPI.DLL
    MSVCR100.dll

  Summary

       72000 .data
       45000 .pdata
      1B6000 .rdata
       32000 .reloc
        1000 .rsrc
      5AF000 .text

This is really odd. There are no dependencies listed that are for Java dlls. The dlls for Java on that version are located in C:\Program Files\Java\jdk1.8.0_242\jre\bin. Is that directory in your PATH?

I believe you must has a typo on the test command. The command works from the Visual studio command prompt without issues.

C:\temp\jpype\project\debug\windows>CL testJVM.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24245 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

testJVM.cpp
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\xlocale(341): warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\exception(359): warning C4577: 'noexcept' used with no exception handling mode specified; termination on exception is not guaranteed. Specify /EHsc
Microsoft (R) Incremental Linker Version 14.00.24245.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:testJVM.exe
testJVM.obj

With the jre directory in the PATH and pointing to the DLL I get.

C:\temp\jpype\project\debug\windows> testJVM.exe "C:\Program Files\Java\jdk1.8.0_242\jre\bin\server\jvm.dll"
Check paths
  SystemDirectory: C:\windows\system32
  WindowsDirectory: C:\windows
Load library
Load entry points
  Entry point found 0000000052C54170
Pack JVM arguments
  Num options: 0
Create JVM
Create Java resources
Destroy JVM
Unload library
Success

Assuming the test script doesn't pick up the error, my suggestion would be to try a different JVM perhaps install Corretto 11. https://docs.aws.amazon.com/corretto/latest/corretto-11-ug/downloads-list.html

Thrameos commented 4 years ago

Did you manage to resolve this?

dwolffenbuttel commented 4 years ago

Unfortunately, no. I did add C:\Program Files\Java\jdk1.8.0_242\jre\bin to PATH, but that did not resolve the problem. I started off with a different JVM, but after it did not turn out to work I switched to this one since this is the version that I have on my pc which does function correctly there.

I ended up giving up on making this work since I could make use of some server capacity at the university. Although not optimal, due to time constraints I had no choice but to work with that, since I had already spend a few days on this problem and I need my time for writing my thesis.

Thanks for your time and effort anyway! I hope a solution may be found soon and people do not need to go through the same struggle as I did.

jackeown commented 3 years ago

We had the same issue when trying to use pynetlogo with jpype. We fixed it by uninstalling and reinstalling the JRE.