jpype package, could be path problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kelemen.viktor

    #1

    jpype package, could be path problem

    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.Syste m.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

  • Rob Wolfe

    #2
    Re: jpype package, could be path problem


    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.Syste m.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:


    HTH,
    Rob

    Comment

    • kelemen.viktor

      #3
      Re: jpype package, could be path problem

      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.Syste m.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:

      >
      HTH,
      Rob

      Comment

      • Rob Wolfe

        #4
        Re: jpype package, could be path problem


        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.Syste m.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

        Comment

        Working...