7

How do we get ctypes.CDLL("jvm.dll") to not find the dll and not give a "module not found" error?

We have verified the paths and can get them through file "open" commands of the jvm.dll - but the exact same paths when given to ctypes gives a "module not found" error.

We also tried editing the registry keys as per this answer.

We have also tried both running a 32 bit version of Python with a 32 bit version of Java as well as trying 64 bit versions.

We are working in Python 2.7.14 on Windows Server 2016.

Why could this be failing and what else can we try? Is there something preventing the Python script from seeing DLLs?


Here is more background:

The reason we are trying to get ctypes to work is because jpype is failing with the same error- and thus they seem foundationally related to the Python modules not being able to see or access the DLL.

When we run the following commands...

>> import ctypes
>> import os
>> os.chdir(r"C:\Program Files (x86)\Java\jre1.8.0_181\bin\client\")
>> ctypes.CDLL("jvm.dll")

...we get "module not found."

Yet, we can reach the file with open commands. For example, this call works from within Python (note it also works for the x86 path used above) to reach the jvm.dll:

>>> fo = open("C:\\Program Files\\Java\\jre1.8.0_181\\bin\\server\\jvm.dll")

But this call via Jpype fails even though is pathed to the same file:

>>> import jpype
>>> jpype.startJVM("C:\\Program Files\\Java\\jre1.8.0_181\\bin\\server\\jvm.dll")

Jpype gives the following error:

File "C:\Python27\lib\site-packages\jpype_core.py", line 70, in startJVM _jpype.startup(jvm, tuple(args), True) RuntimeError: Unable to load DLL [C:\Program Files\Java\jre1.8.0_181\bin\server\jvm.dll], error = The specified module could not be found. at native\common\include\jp_platform_win32.h:58

The reason we are using jpype is we are trying to get Jaydebeapi working to create a JDBC connection to a database.

How do we enable ctypes (and presumably thus jpype) to find and use the jvm.dll?

Praxiteles
  • 5,802
  • 9
  • 47
  • 78
  • Disclaimer: complete guess... Have you tried installing the jre outside `program files` (`c:\java\...` etc)? Could be file permission / windows file protection issue. – MisterSmith Jul 23 '18 at 01:02

1 Answers1

0

Our answer to solving this was to move from using the Python 2.7 interpreter to using Jython.

Using Jython, we were able to use the Jadebeapi library and connect to the database over JDBC.

Praxiteles
  • 5,802
  • 9
  • 47
  • 78