Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
290 views
in Technique[技术] by (71.8m points)

java - Accessing JVM from python

>>> import boilerpipe
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:Anacondalibsite-packagesoilerpipe\__init__.py", line 10, in <module>
    jpype.startJVM(jpype.getDefaultJVMPath(), "-Djava.class.path=%s" % os.pathsep.join(jars))
  File "C:Anacondalibsite-packagesjpype\_core.py", line 50, in startJVM
    _jpype.startup(jvm, tuple(args), True)
RuntimeError: Unable to load DLL [C:Program FilesJavajre7inclientjvm.dll], error = The specified module could not be found.
 at nativecommonincludejp_platform_win32.h:58

Tried: Reinstalling jvm

>> import ctypes
>> import os
>> os.chdir(r"<path to Java bin client folder>")
>> ctypes.CDLL("jvm.dll")
Still unable to fix

Edit: Tried code below, still stuck:

from py4j.java_gateway import JavaGateway gateway = JavaGateway() It gives the same error as before.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Check Please !

  1. Give a true path ("C:\Program Files\Java\jre7\binclient\jvm.dll")
  2. Check all 32 or 64 bit (my offer always use 32bit Anaconda,JRE7,Python etc.)
  3. Install pywin32 (of course python2.7.9)
  4. Give permission to jvm.dll(can run)
  5. After all is ok, try: import ctypes ctypes.CDLL('C:\Program Files\Java\jre7\bin\client\jvm.dll')

***Maybe can't throw the hook of some java versions i used jre-7u55-windows-i586.exe

i hope helpful ! Best regards !

Works on wine(no bug): enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...