By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,771 Members | 1,741 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,771 IT Pros & Developers. It's quick & easy.

jpype package, could be path problem

P: n/a
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:
python
>>import jpype
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

Sep 20 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a

kelemen.viktor wrote:
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

Sep 20 '06 #2

P: n/a
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
Rob Wolfe wrote:
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
Sep 20 '06 #3

P: n/a

kelemen.viktor wrote:
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

Sep 20 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.