Thread: [Py4j-users] Help Requested: error when accessing jvm for basic sample
Status: Beta
Brought to you by:
barthe
From: Sean S. <sea...@gm...> - 2011-04-19 00:07:21
|
HI All, I'm just getting started with Py4J, basically just trying to call a jar. I'm having trouble with the basic sample however: >>> from py4j.java_gateway import JavaGateway >>> gateway = JavaGateway() # connect to the JVM >>> random = gateway.jvm.java.util.Random() # create a java.util.Random instance >>> number1 = random.nextInt(10) # call the Random.nextInt method >>> number2 = random.nextInt(10) >>> print(number1,number2) (2, 7) >>> addition_app = gateway.entry_point # get the AdditionApplication instance >>> addition_app.addition(number1,number2) # call the addition method 9 I keep getting the following error: [Errno 10061] No connection could be made because the target machine actively refused it I'm on python 2.71 for windows i have jre6 se installed have set path. cheers, Sean |
From: Barthelemy D. <ba...@cs...> - 2011-04-19 00:21:45
|
Hi Sean, this error means that the python interpreter cannot connect to the jvm either because: 1- The jvm is not yet started so nothing is listening on the default py4j port. 2- You have a firewall blocking the port. You need to start the java program in the example and then, you can start your python interpreter (not the other way around). If you don't have a firewall and if you started the Java program before running the interpreter, we will need more information to help you (e.g., how did you start the Java program, what is the output of the "netstat" command in a command prompt after starting the Java program, etc.). Barthélémy On Mon, April 18, 2011 8:07 pm, Sean Silvestri wrote: > HI All, > I'm just getting started with Py4J, basically just trying to call a > jar. I'm having trouble with the basic sample however: > > >>>> from py4j.java_gateway import JavaGateway gateway = JavaGateway() >>>> # connect to the JVM >>>> random = gateway.jvm.java.util.Random() # create a >>>> java.util.Random instance number1 = random.nextInt(10) >>>> # call the Random.nextInt method >>>> number2 = random.nextInt(10) print(number1,number2) > (2, 7) > >>>> addition_app = gateway.entry_point # get the >>>> AdditionApplication instance >>>> addition_app.addition(number1,number2) # call the addition method >>>> > 9 > > > I keep getting the following error: [Errno 10061] No connection could > be made because the target machine actively refused it > > I'm on python 2.71 for windows i have jre6 se installed have set path. > cheers, Sean > > > ------------------------------------------------------------------------- > ----- > Benefiting from Server Virtualization: Beyond Initial Workload > Consolidation -- Increasing the use of server virtualization is a top > priority.Virtualization can reduce costs, simplify management, and improve > application availability and disaster protection. Learn more about > boosting the value of server virtualization. > http://p.sf.net/sfu/vmware-sfdev2dev > _______________________________________________ > Py4j-users mailing list > Py4...@li... > https://lists.sourceforge.net/lists/listinfo/py4j-users > > |
From: Barthelemy D. <ba...@cs...> - 2011-04-19 09:55:42
|
Hi Sean, The way Py4J works is that python code is executed in a Python interpreter and Java code is invoked by a Java Virtual Machine. Both the Python interpreter and the JVM must be started prior to using Py4J. In other words, Py4J won't start a JVM to execute code in a jar file. To run the example, first, locate the py4j.jar and your jar and execute this command (using the right path): java -cp path\to\py4j.jar;path\to\yourlib.jar \ py4j.examples.AdditionApplication Then, open a python interpreter and try the example code, it should work. You should also be able to access the code in your jar file. Hope this helps, Barthélémy On 04/18/2011 08:43 PM, Sean Silvestri wrote: > Hi Barthelemy, > Interesting, I did not start any Java program. I must have > misunderstood the premise of the module. > My main goal is to simply call into a java jar file that I've > registered e.g. the classpath. > > Since that was not working I just resorted to the basic sample on the > web site using the .java.util.Random class (see below) > I'm simply wanting to interface with a jar file in order to call the > java methods. > gateway = JavaGateway() # connect to the JVM >>>> random = gateway.jvm.java.util.Random() # create a java.util.Random instance >>>> number1 = random.nextInt(10) # call the Random.nextInt method >>>> number2 = random.nextInt(10) >>>> print(number1,number2) > (2, 7) > > I had also turned off my firewall but still had gotten the error i had > mentiond ( [Errno 10061] No connection could be made because the > target machine actively refused it). > > What would be the steps to be able to call java code situated in a > .jar file from a python script using py4j? > many thanks, > Sean > > > > On Mon, Apr 18, 2011 at 5:21 PM, Barthelemy Dagenais<ba...@cs...> wrote: >> Hi Sean, >> >> this error means that the python interpreter cannot connect to the jvm >> either because: >> >> 1- The jvm is not yet started so nothing is listening on the default py4j >> port. >> >> 2- You have a firewall blocking the port. >> >> You need to start the java program in the example and then, you can start >> your python interpreter (not the other way around). >> >> If you don't have a firewall and if you started the Java program before >> running the interpreter, we will need more information to help you (e.g., >> how did you start the Java program, what is the output of the "netstat" >> command in a command prompt after starting the Java program, etc.). >> >> Barthélémy >> >> On Mon, April 18, 2011 8:07 pm, Sean Silvestri wrote: >>> HI All, >>> I'm just getting started with Py4J, basically just trying to call a >>> jar. I'm having trouble with the basic sample however: >>> >>> >>>>>> from py4j.java_gateway import JavaGateway gateway = JavaGateway() >>>>>> # connect to the JVM >>>>>> random = gateway.jvm.java.util.Random() # create a >>>>>> java.util.Random instance number1 = random.nextInt(10) >>>>>> # call the Random.nextInt method >>>>>> number2 = random.nextInt(10) print(number1,number2) >>> (2, 7) >>> >>>>>> addition_app = gateway.entry_point # get the >>>>>> AdditionApplication instance >>>>>> addition_app.addition(number1,number2) # call the addition method >>>>>> >>> 9 >>> >>> >>> I keep getting the following error: [Errno 10061] No connection could >>> be made because the target machine actively refused it >>> >>> I'm on python 2.71 for windows i have jre6 se installed have set path. >>> cheers, Sean >>> >>> >>> ------------------------------------------------------------------------- >>> ----- >>> Benefiting from Server Virtualization: Beyond Initial Workload >>> Consolidation -- Increasing the use of server virtualization is a top >>> priority.Virtualization can reduce costs, simplify management, and improve >>> application availability and disaster protection. Learn more about >>> boosting the value of server virtualization. >>> http://p.sf.net/sfu/vmware-sfdev2dev >>> _______________________________________________ >>> Py4j-users mailing list >>> Py4...@li... >>> https://lists.sourceforge.net/lists/listinfo/py4j-users >>> >>> >> >> >> |
From: Barthelemy D. <ba...@cs...> - 2011-04-19 15:27:25
|
Ahhh... sorry, I'm not often working on Windows and I just found out that the doc is incorrect: The jar file should be in: Python27\Lib\site-packages\Py4J-0.6-py2.7.egg\share\py4j I'll have to check whether it is caused by Windows or easy_install (I usually use pip). Barthélémy On Tue, April 19, 2011 11:13 am, Sean Silvestri wrote: > Interesting I did the easy install option but cant seem to find the > py4j.jar file on my system. could it be in another location other than > python27\share as that directory doesnt exist. cheers, Sean > > > On Tue, Apr 19, 2011 at 2:55 AM, Barthelemy Dagenais <ba...@cs...> > wrote: > >> Hi Sean, >> >> >> The way Py4J works is that python code is executed in a Python >> interpreter and Java code is invoked by a Java Virtual Machine. Both the >> Python >> interpreter and the JVM must be started prior to using Py4J. In other >> words, Py4J won't start a JVM to execute code in a jar file. >> >> >> To run the example, first, locate the py4j.jar and your jar and execute >> this command (using the right path): >> >> java -cp path\to\py4j.jar;path\to\yourlib.jar \ >> py4j.examples.AdditionApplication >> >> Then, open a python interpreter and try the example code, it should >> work. >> >> You should also be able to access the code in your jar file. >> >> >> Hope this helps, >> Barthélémy >> >> >> On 04/18/2011 08:43 PM, Sean Silvestri wrote: >> >>> >>> Hi Barthelemy, >>> Interesting, I did not start any Java program. I must have >>> misunderstood the premise of the module. My main goal is to simply call >>> into a java jar file that I've registered e.g. the classpath. >>> >>> Since that was not working I just resorted to the basic sample on the >>> web site using the .java.util.Random class (see below) I'm simply >>> wanting to interface with a jar file in order to call the java >>> methods. gateway = JavaGateway() # connect to the >>> JVM >>> >>>>>> >>>>>> random = gateway.jvm.java.util.Random() # create a >>>>>> java.util.Random instance number1 = random.nextInt(10) >>>>>> # call the Random.nextInt >>>>>> method number2 = random.nextInt(10) print(number1,number2) >>> >>> (2, 7) >>> >>> >>> I had also turned off my firewall but still had gotten the error i >>> had mentiond ( [Errno 10061] No connection could be made because the >>> target machine actively refused it). >>> >>> What would be the steps to be able to call java code situated in a >>> .jar file from a python script using py4j? >>> many thanks, Sean >>> >>> >>> >>> >>> On Mon, Apr 18, 2011 at 5:21 PM, Barthelemy >>> Dagenais<ba...@cs...> >>> wrote: >>> >>>> >>>> Hi Sean, >>>> >>>> >>>> this error means that the python interpreter cannot connect to the >>>> jvm either because: >>>> >>>> 1- The jvm is not yet started so nothing is listening on the >>>> default py4j port. >>>> >>>> 2- You have a firewall blocking the port. >>>> >>>> >>>> You need to start the java program in the example and then, you can >>>> start your python interpreter (not the other way around). >>>> >>>> If you don't have a firewall and if you started the Java program >>>> before running the interpreter, we will need more information to >>>> help you (e.g., how did you start the Java program, what is the >>>> output of the "netstat" command in a command prompt after starting >>>> the Java program, etc.). >>>> >>>> Barthélémy >>>> >>>> >>>> On Mon, April 18, 2011 8:07 pm, Sean Silvestri wrote: >>>> >>>>> >>>>> HI All, >>>>> I'm just getting started with Py4J, basically just trying to call >>>>> a jar. I'm having trouble with the basic sample however: >>>>> >>>>> >>>>>>>> from py4j.java_gateway import JavaGateway gateway = >>>>>>>> JavaGateway() >>>>>>>> # connect to the JVM >>>>>>>> random = gateway.jvm.java.util.Random() # create a >>>>>>>> java.util.Random instance number1 = random.nextInt(10) # >>>>>>>> call the Random.nextInt method number2 = random.nextInt(10) >>>>>>>> print(number1,number2) >>>>> >>>>> (2, 7) >>>>> >>>>> >>>>>>>> addition_app = gateway.entry_point # get the >>>>>>>> AdditionApplication instance >>>>>>>> addition_app.addition(number1,number2) # call the >>>>>>>> addition method >>>>>>>> >>>>> 9 >>>>> >>>>> >>>>> >>>>> I keep getting the following error: [Errno 10061] No connection >>>>> could be made because the target machine actively refused it >>>>> >>>>> I'm on python 2.71 for windows i have jre6 se installed have set >>>>> path. cheers, Sean >>>>> >>>>> >>>>> >>>>> ----------------------------------------------------------------- >>>>> -------- >>>>> ----- >>>>> Benefiting from Server Virtualization: Beyond Initial Workload >>>>> Consolidation -- Increasing the use of server virtualization is a >>>>> top priority.Virtualization can reduce costs, simplify management, >>>>> and improve application availability and disaster protection. >>>>> Learn more about >>>>> boosting the value of server virtualization. >>>>> http://p.sf.net/sfu/vmware-sfdev2dev >>>>> _______________________________________________ >>>>> Py4j-users mailing list >>>>> Py4...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/py4j-users >>>>> >>>>> >>>>> >>>> >>>> >>>> >> >> > |