jpype

python中调用java代码

天涯浪子 提交于 2020-04-26 22:41:13
简介: Python 作为一种灵活的软件开发语言在当今被广泛使用。在软件开发过程中,有时需要在 Python 项目中利用既有的 Java 代码,已达到节省时间和开发成本的目的。因此,找到一个 Python 代码调用 Java 代码的桥梁是非常有意义的。 JPype 就是这样的一个工具,利用它可以使 Python 程序方便的调用 Java 代码,从而扩充 Python 语言的能力,弥补 Python 语言的不足。 本文介绍了如何利用 JPype 整合 Python 程序和 Java 程序的一些基本方法。 概览: JPype 是一个能够让 python 代码方便地调用 Java 代码的工具,从而克服了 python 在某些领域(如服务器端编程)中的不足。 首先安装的jdk和python和第三方包jpype都是32位或者是64位。 前提条件:jdk和python都已经安装完毕 python中操作虚拟机的相关方法: 启动 JVM JPype 提供的 startJVM() 函数的作用是启动 JAVA 虚拟机,所以在后续的任何 JAVA 代码被调用前,必须先调用此方法启动 JAVA 虚拟机。 jpype.startJVM() 的定义 startJVM(jvm, * args) # jpype.startJVM() 的参数 # 参数 1: jvm, 描述你系统中 jvm.dll 文件所在的路径

如何安装带有.whl文件的Python软件包?

女生的网名这么多〃 提交于 2020-04-24 06:06:57
问题: I'm having trouble installing a Python package (specifically, JPype1 0.5.7) on my Windows machine, and would like to install it with Christoph Gohlke's Window binaries. 我在Windows机器上安装Python软件包(特别是JPype1 0.5.7)时遇到问题,并且想用Christoph Gohlke的Window二进制文件安装它。 (Which, to my experience, alleviated much of the fuss for many other package installations.) (根据我的经验,这减轻了许多其他软件包安装的麻烦。) However, while Christoph used to provide .exe files in the past, recently it seems he's uploading .whl files instead. 但是,尽管Christoph过去曾经提供过.exe文件,但最近看来他正在上传.whl文件。 http://www.lfd.uci.edu/~gohlke/pythonlibs/#jpype http://www

JPype won't compile properly

坚强是说给别人听的谎言 提交于 2020-01-24 14:19:05
问题 So I am having trouble compiling a very simple python script using JPype. My code goes like: from jpype import * startJVM(getDefaultJVMPath(), "-ea") java.lang.System.out.println("hello world") shutdownJVM() and when I run it I receive an error saying: Traceback (most recent call last): File "test.py", line 2, in <module> startJVM(getDefaultJVMPath(), "-ea") File "/usr/lib/pymodules/python2.7/jpype/_core.py", line 44, in startJVM _jpype.startup(jvm, tuple(args), True) RuntimeError: Unable to

Different / better approaches for calling python function from Java

天涯浪子 提交于 2020-01-10 05:18:25
问题 I am quite new to python and am trying to call python's function from java. My primary requirements are these: call should be transparent, in the sense that it should not require modifying .py file simply to enable it to be called from java. I might be given any python file with some functions inside it. I should be able to call any of these functions without requiring to modify .py file. I want to be able to send arguments of both primitive types ( int , String , floats etc.) or non

Difficulties starting JVM in Python using jpype

我是研究僧i 提交于 2020-01-02 08:34:50
问题 I have been using jpype to integrate with some java code using python lately and have been having no real issues. I am now attempting to set up my stack on a new system and am running into difficulties. I am running 32-bit Python 3.6.5 and 32-bit oracle Java 1.8 update 171. Python and jpype have been installed using conda ( conda create -n venv -c conda-forge python jpype1 arrow ), and jpype.getDefaultJVMPath() returns the expected path ( C:\Program Files (x86)\Java\jre1.8.0_171\bin\client

Installing jpype in Mountain Lion

戏子无情 提交于 2020-01-01 05:18:08
问题 I am trying to install jpype in Mountain Lion. I followed all the steps suggested in this post: How to install JPype on OS X Lion to use with Neo4j? However, there is a glitch with Mountain Lion. I have modified the setupMacOSX() function as follows: /Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/JavaVM.framework/ But when I run $ sudo python setup.py install I get the following error: src/native/common/include/jpype.h:45:10: fatal error: 'jni.h' file not found I have located the

Is -cp option not working in JPype?

依然范特西╮ 提交于 2019-12-25 03:45:06
问题 I am using jpype with Python 2.7 (jpype distribution from the university of california) and I'm trying to use a Java class from a jar file. It works fine if I start the JVM with startJVM(getDefaultJVMPath(), "-ea", "-Djava.class.path=D:/jmf.jar") However, if I am using startJVM(getDefaultJVMPath(), "-ea", "-cp", "D:/jmf.jar") or startJVM(getDefaultJVMPath(), "-ea", "-cp D:/jmf.jar") the classes from that jar are not found... I also tried setting the classpath with set CLASSPATH=".;D:\jmf.jar"

Calling a jar file from Python using JPype-total newbie query

狂风中的少年 提交于 2019-12-23 01:11:14
问题 So I have been using subprocess.call to run a jar file from Python as so: subprocess.call(['java','-jar','jarFile.jar',-a','input_file','output_file']) where it writes the result to an external output_file file. and -a is an option. I now want to analyse output_file in python but want to avoid opening the file again. So I want to run jarFile.jar as a Python function, like: output=jarFile(input_file) I have installed JPype and got it working, I have set the class path and started the JVM

Installing Stanford Parser's Python interface: error: command 'gcc' failed with exit status 1 rake aborted

﹥>﹥吖頭↗ 提交于 2019-12-13 06:10:32
问题 I'd like to install the stanford parser's python interface. http://projects.csail.mit.edu/spatial/Stanford_Parser When running rake setup to install jpype first, I keep ge In file included from src/native/common/jp_reference.cpp:1:0: src/native/common/include/jpype.h:45:17: schwerwiegender Fehler: jni.h: Datei oder Verzeichnis nicht gefunden Kompilierung beendet. error: command 'gcc' failed with exit status 1 rake aborted! The error message is english-german-mixed. It says: heavy failure: jni

Fatal error: jni.h: No such file or directory while installing jPype

坚强是说给别人听的谎言 提交于 2019-12-13 04:37:50
问题 I am trying to install JPype on Ubuntu 13.04. I have Oracle Java 1.7 installed. But when I do so, I get the following error: src/native/common/include/jpype.h:45:17: fatal error: jni.h: No such file or directory Unlike a lot of similar questions on stackoverflow, the file isn't present on my system i.e. locate jni.h returns nothing. Yes, I have run sudo updatedb before issuing above command. 回答1: You have installed a JRE and not a JDK. To compile JNI native code, you need to install a JDK,