jpype package, could be path problem

K

kelemen.viktor

Hello!

Im a quite newbie in the python world.
I have some problem with packages, i installed the jpype package
according to its intructions.
To test ive written:
everything worked correctly but when i wrote a short script:
"
from jpype import *

jpype.startJVM('/usr/lib/jvm/java-1.5.0-sun-1.5.0.06/jre/lib/i386/client/libjvm.so','-ea')
java.lang.System.out.println("hello world")
shutdownJVM()
"
and tried to run it this's got:

"
Traceback (most recent call last):
File "/home/kelemen/workspace/JPype/src/helloAgent.py", line 3, in ?

jpype.startJVM('/usr/lib/jvm/java-1.5.0-sun-1.5.0.06/jre/lib/i386/client/libjvm.so','-ea')
NameError: name 'jpype' is not defined
"

What would be the reason?

thanks in advanced
Viktor
 
R

Rob Wolfe

kelemen.viktor said:
everything worked correctly but when i wrote a short script:
"
from jpype import *

jpype.startJVM('/usr/lib/jvm/java-1.5.0-sun-1.5.0.06/jre/lib/i386/client/libjvm.so','-ea')
java.lang.System.out.println("hello world")
shutdownJVM()
"
and tried to run it this's got:

"
Traceback (most recent call last):
File "/home/kelemen/workspace/JPype/src/helloAgent.py", line 3, in ?

jpype.startJVM('/usr/lib/jvm/java-1.5.0-sun-1.5.0.06/jre/lib/i386/client/libjvm.so','-ea')
NameError: name 'jpype' is not defined
"

What would be the reason?

Consider this:

# bad style (potential name clash)
from jpype import *
startJVM('/usr/lib/jvm/java-1.5.0-sun-1.5.0.06/jre/lib/i386/client/libjvm.so','-ea')

# that's better
import jpype
jpype.startJVM('/usr/lib/jvm/java-1.5.0-sun-1.5.0.06/jre/lib/i386/client/libjvm.so','-ea')

# for long names of modules
import jpype as jp
jp.startJVM('/usr/lib/jvm/java-1.5.0-sun-1.5.0.06/jre/lib/i386/client/libjvm.so','-ea')

And see this:
http://docs.python.org/tut/node8.html

HTH,
Rob
 
K

kelemen.viktor

Hi

thanks for your suggestions

ive modified the sample code

"
import jpype
from jpype import *

jpype.startJVM('/usr/lib/jvm/java-1.5.0-sun-1.5.0.06/jre/lib/i386/client/libjvm.so','-ea')
java.lang.System.out.println("hello world")
shutdownJVM()
"

and its working. It seems to be quite strange.
What would be the difference between the two import?

Viktor
 
R

Rob Wolfe

kelemen.viktor said:
Hi

thanks for your suggestions

ive modified the sample code

You've modified it incorrect.
"
import jpype
from jpype import *

You should use "import jpype" OR "from jpype import *" (not
recommended)
but NOT BOTH.
jpype.startJVM('/usr/lib/jvm/java-1.5.0-sun-1.5.0.06/jre/lib/i386/client/libjvm.so','-ea')
java.lang.System.out.println("hello world")
shutdownJVM()
"

and its working. It seems to be quite strange.
What would be the difference between the two import?

1. "import jpype"

This does not enter the name of the function startJVM defined in jpype
directly in the current symbol table; it only enters the module name
jpype there.
Using the module name you can access the function like that:

jpype.startJVM()

2. "from jpype import"

This enters the name of the function startJVM in the currrent symbol
table,
so you can access the function just like that:

startJVM()

And have you read this: http://docs.python.org/tut/node8.html ?

HTH,
Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top