Title: odd behavior when importing * from Java packages/modules when using the embedded interpreter
Type: behaviour Severity: normal
Components: Library Versions: Jython 2.5
Status: closed Resolution: invalid
Dependencies: Superseder:
Assigned To: fwierzbicki Nosy List: akong, bvan, fwierzbicki, sltanimoto, tzellman, zyasoft
Priority: high Keywords:

Created on 2009-06-19.15:45:03 by tzellman, last changed 2014-06-25.16:05:20 by zyasoft.

File name Uploaded Description Edit Remove bvan, 2012-03-02.00:24:21 Import Test for javax.mail
msg4824 (view) Author: (tzellman) Date: 2009-06-19.15:45:02
I am using the Jython 2.5 release posted on SourceForge.
I am embedding the interpreter inside my Java code. 

Code that worked perfectly under Jython 2.2 is now failing with an
ImportError. Jython is failing to find Java-based modules after I import
* from a parent package. For example:

from import *
from import *
from import *

Jython fails with this error message:
"ImportError: No module named checks"

If I instead strip out the * imports and import objects directly from
the modules, everything works normally.

A little more insight into what I am doing: I create the interpreter,
then pass it a string of Python code that essentially loads a
directory/module where Jython plug-in scripts are located. Those scripts
then import java modules available within the current Java process.
msg5454 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2010-01-25.16:21:32
Hi tzellman: I know you submitted this bug a long time ago, but if you are still around, if you could upload test (as small as possible would help) that shows off this bug I can take a look at it.
msg5455 (view) Author: (tzellman) Date: 2010-01-26.15:46:03
Thanks for responding Frank. I actually just tried 3 different methods of calling/importing python from within Java. You can view what I tested here:

For my simple test case, using Jython 2.5.1 worked as expected. :)

I also tried Jython 2.5.0, which, aside from not having the interpreter.compile() method, did NOT work. So, it looks like the problem I was having in Jython 2.5.0 were fixed since then. Jython 2.5.0 gives this error stacktrace:

Traceback (most recent call last):
  File "", line 9, in <module>
  File "", line 6, in run
    print Utils2.randomString(10)
LookupError: no codec search functions registered: can't find encoding

	at org.python.core.PyException.fillInStackTrace(
	at java.lang.Throwable.<init>(
	at java.lang.Exception.<init>(
	at java.lang.RuntimeException.<init>(
	at org.python.core.PyException.<init>(
	at org.python.core.PyException.<init>(
	at org.python.core.PyException.<init>(
	at org.python.core.codecs.lookup(
	at org.python.core.codecs.getEncoder(
	at org.python.core.codecs.encode(
	at org.python.core.PyString.str_encode(
	at org.python.core.PyString.encode(
	at org.python.core.StdoutWrapper.print(
	at org.python.core.StdoutWrapper.println(
	at org.python.core.Py.println(
	at org.python.pycode._pyx0.call_function(
	at org.python.core.PyFunction.__call__(
	at org.python.pycode._pyx0.f$0(
	at org.python.pycode._pyx0.call_function(
	at org.python.core.Py.runCode(
	at org.python.core.__builtin__.execfile_flags(
	at org.python.util.PythonInterpreter.execfile(
	at gist.JythonTest.runFile(
	at gist.JythonTest.main(
msg5935 (view) Author: Steve Tanimoto (sltanimoto) Date: 2010-08-02.18:27:32
Here is a further comment on this.  I am also embedding the interpreter (2.5.1 release).  When I execute
import javax.imageio
It works on a Macbook Pro running Leopard.
On Windows Vista, if I do it in the Jython shell (not the embedded interpreter) it also works.
But (still on Windows Vista) in the embedded interpreter, it fails with:
ImportError: No module named imageio
As reported by tzellmann, I can work around this by using
import javax.imageio.ImageIO as ImageIO
and that works OK.
msg6786 (view) Author: Brian (bvan) Date: 2012-03-02.00:24:20

Hopefully I didn't botch this report up... this is my first time reporting here.  I'm pretty sure this is the same bug I'm experiencing, so I thought I'd go ahead and add my test.

Basically, it fails on executing:
from javax.mail import *

Succeeds for:
from javax.mail import Session

...*and then* seems okay after I use the more explicit import if I revert to the * import:
from javax.mail import *

javax.mail has only classes and packages/directories, no mixed files, in it's path.

I think you'll need javax.mail for this test added to the classpath, I used version 1.4.1.
msg7747 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2013-02-25.20:04:35
Assigning to myself so hopefully I finally get to this.
msg8694 (view) Author: Jim Baker (zyasoft) Date: 2014-06-19.01:01:43
This sounds like the well known problem that Jython cannot import in such a fashion if it has not scanned and built the package cache. See
Date User Action Args
2014-06-25 16:05:20zyasoftsetstatus: pending -> closed
2014-06-19 01:01:43zyasoftsetstatus: open -> pending
resolution: invalid
messages: + msg8694
nosy: + zyasoft
2013-02-25 20:04:35fwierzbickisetpriority: high
assignee: fwierzbicki
messages: + msg7747
versions: + Jython 2.5, - 2.5.2
2012-03-02 00:24:21bvansetfiles: +
nosy: + bvan
messages: + msg6786
versions: + 2.5.2
2010-08-02 18:27:34sltanimotosetnosy: + sltanimoto
messages: + msg5935
2010-06-18 04:51:46akongsetnosy: + akong
2010-01-26 15:46:04tzellmansetmessages: + msg5455
2010-01-25 16:21:33fwierzbickisetnosy: + fwierzbicki
messages: + msg5454
2009-06-19 15:45:03tzellmancreate