Issue1383

classification
Title: odd behavior when importing * from Java packages/modules when using the embedded interpreter
Type: behaviour Severity: normal
Components: Library Versions: Jython 2.5
process
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.

Files
File name Uploaded Description Edit Remove
JythonTest.java bvan, 2012-03-02.00:24:21 Import Test for javax.mail
Messages
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 my.java.package import *
from my.java.package.checks import *
from my.java.package.actions 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: http://gist.github.com/286908

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:

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

	at org.python.core.PyException.fillInStackTrace(PyException.java:70)
	at java.lang.Throwable.<init>(Throwable.java:181)
	at java.lang.Exception.<init>(Exception.java:29)
	at java.lang.RuntimeException.<init>(RuntimeException.java:32)
	at org.python.core.PyException.<init>(PyException.java:46)
	at org.python.core.PyException.<init>(PyException.java:43)
	at org.python.core.PyException.<init>(PyException.java:61)
	at org.python.core.codecs.lookup(codecs.java:80)
	at org.python.core.codecs.getEncoder(codecs.java:209)
	at org.python.core.codecs.encode(codecs.java:187)
	at org.python.core.PyString.str_encode(PyString.java:2429)
	at org.python.core.PyString.encode(PyString.java:2424)
	at org.python.core.StdoutWrapper.print(StdoutWrapper.java:111)
	at org.python.core.StdoutWrapper.println(StdoutWrapper.java:203)
	at org.python.core.Py.println(Py.java:1329)
	at org.python.pycode._pyx0.run$1(test.py:6)
	at org.python.pycode._pyx0.call_function(test.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:117)
	at org.python.core.PyFunction.__call__(PyFunction.java:307)
	at org.python.pycode._pyx0.f$0(test.py:9)
	at org.python.pycode._pyx0.call_function(test.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1197)
	at org.python.core.__builtin__.execfile_flags(__builtin__.java:538)
	at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:156)
	at gist.JythonTest.runFile(JythonTest.java:25)
	at gist.JythonTest.main(JythonTest.java:84
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
Hi, 

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 http://stackoverflow.com/questions/1681849/why-does-jython-refuse-to-find-my-java-package
History
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: + JythonTest.java
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