jython ImportError: No module named

15,307

Solution 1

In your shell script use:

export CLASSPATH=TestModule.jar:$CLASSPATH
jython ...

In my case setting CLASSPATH is enough. Remember to use full path name and remember to use good .jar name (testmodule.jar and TestModul.jar are different). Maybe you use wrong file rights. Try file command to check if you can read that file. Example for one of jars I use:

mn$ file junit-4.1.jar
junit-4.1.jar: Zip archive data, at least v2.0 to extract

Solution 2

I was getting same issue.

I tried below function and worked well!

>>> import sys 
>>> sys.path.append('/path/to/helloworld.jar')
>>> from com.leosoto import HelloWorld

For more info:

http://blog.leosoto.com/2008/07/jython-import-logic.html

Share:
15,307

Related videos on Youtube

Kat Farrell
Author by

Kat Farrell

Updated on September 15, 2022

Comments

  • Kat Farrell
    Kat Farrell over 1 year

    I'm new to jython and failing utterly at importing a java class within a jar.

    What I am trying to do is write a wrapper shell script which calls a jython script. I can not allowed to edit the jython at all, so adding jars to sys.path within that jython script is not possible.

    Error y", line 17, in from com.polarland.testModule.cache import CacheInterface ImportError: No module named polarland

    I've added the jar which contains the above package with name of TestModule.jar to PATH, ClASSPATH and JYTHONPATH with no avail. I'm worried this is due to the name of the jar but am not sure.

    Any advice would be greatly appreciated!!

  • Kat Farrell
    Kat Farrell about 11 years
    Thank you for your answer my issue was different jar names. Takes for taking the time to respond!
  • Per Lundberg
    Per Lundberg over 2 years
    Link is dead, unfortunately.