Issue542389

classification
Title: "cannot import name" and other problems
Type: Severity: normal
Components: Jythonc compiler Versions:
Milestone:
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: fwierzbicki, juu, nobody
Priority: low Keywords:

Created on 2002-04-11.08:09:19 by juu, last changed 2009-03-13.23:34:21 by fwierzbicki.

Files
File name Uploaded Description Edit Remove
jythonc_module_import_problem.zip juu, 2002-04-11.08:09:19 Some files and logs to provide more context
Messages
msg641 (view) Author: Juu (juu) Date: 2002-04-11.08:09:19
Here's my story - it's a long one, but I'm running 
into a lot of problems.

I have a 80-module application, written in Jython. 
Some of the modules contain classes, while some are 
just a collection of methods.

It works fine in the interpreter, but when compiled, 
it misbehaves.

a) JythonC wouldn't compile from inner 
packages/directories correctly, just from root. As a 
workaround, I moved my main executable to root.

b) I had some "code" and "sys" includes and it 
wouldn't properly include those modules even with 
--deep or --all. 

I placed "import code" and etc. in my main executable 
(compile root) and it started to work, but now 
complained about other includes:

Java Traceback:

        at org.python.core.Py.ImportError(Py.java:180)
        at org.python.core.imp.importFromAs
(imp.java:593)
        at TR$_PyInner.main$1(TR.java:36)
        at TR$_PyInner.call_function(TR.java:28)
        at org.python.core.PyTableCode.call
(PyTableCode.java:198)
        at org.python.core.PyCode.call(PyCode.java:13)
        at org.python.core.imp.createFromCode
(imp.java:165)
        at org.python.core.Py.runMain(Py.java:818)
        at TR.main(TR.java:54)
Traceback (innermost last):
  File "C:\python\TR.py", line 0, in main
ImportError: cannot import name Log

c) I finally got it to work by including around 20 
includes in my main file.
I also made sure that modules in directory "m" never 
do "from m.SomeClass import SomeClass", but 
always "from SomeClass import SomeClass". This seemed
to help with all the "missing module" problems, but 
not with all "cannot import name" problems.

d) For example, I cannot use my other compiled classes 
directly:

C:\python>run_custom_from_jar.bat juudb.DbResultSet

C:\python>java -
Dpython.path=C:\programming\jython\lib -c
p 
C:\programming\jython\jython.jar;tr.jar;C:\programming\
java\lib\interclien
t.jar juudb.DbResultSet
Java Traceback:

        at org.python.core.Py.ImportError(Py.java:180)
        at org.python.core.imp.importFromAs
(imp.java:593)
        at juudb.DbResultSet$_PyInner.main$9
(DbResultSet.java:200)
        at juudb.DbResultSet$_PyInner.call_function
(DbResultSet.java:64)
        at org.python.core.PyTableCode.call
(PyTableCode.java:198)
        at org.python.core.PyCode.call(PyCode.java:13)
        at org.python.core.imp.createFromCode
(imp.java:165)
        at org.python.core.Py.runMain(Py.java:818)
        at juudb.DbResultSet.main(DbResultSet.java:217)
Traceback (innermost last):
  File "C:\python\juudb\DbResultSet.py", line 0, in 
main
ImportError: cannot import name LowerDict

-------
from java.lang import StringBuffer
from juulib.LowerDict import LowerDict
from juulib import Log
from javax.xml.parsers import DocumentBuilderFactory

class DbResultSet:
	... more code here ...
-------

On the other hand, the class it complains about can be 
used just fine:

C:\python>run_custom_from_jar.bat juulib.LowerDict

C:\python>java -
Dpython.path=C:\programming\jython\lib -cp 
C:\programming\jython\jython.jar;tr.jar;C:\programming\
java\lib\interclient.jar juulib.LowerDict

--------------

class LowerDict:
	__vdict = None
	__vdict_name = locals().keys()[0]

        def __init__(self, initData = {}):
            self.__dict__[self.__vdict_name] = {}
	    for i in initData.keys():
		self[i] = initData[i]

        def __getitem__(self, key):
            return self.__vdict[self.convert(key)]

        def __setitem__(self, key, value):
            self.__vdict[self.convert(key)] = value

        def __delitem__(self, key):
            del self.__vdict[self.convert(key)]

       	def __setattr__(self, name, value):
	    self.__vdict.name = value

	def __getattr__(self, name):
#	    print "returning", name
	    return getattr(self.__vdict, name)

	def __repr__(self):
	    return repr(self.__vdict)

	def convert(self, what):
	    if isinstance(what, type("")):
		return what.lower()

	    return what

	def has_key(self, which):
	    return self.__vdict.has_key(self.convert
(which))

------------

e) I tried to recreate these problems on a smaller 
scale.

I have included the relevant files and have recreated 
2 problems for which I see workarounds - the "only 
compile root classes" (point a) and "misses a 
module import" (partial points b and c).

I haven't recreated that "cannot import name" problem 
on a smaller scale, but perhaps my description helps 
anyway. I'm even starting to think that perhaps 
there's some limit to the depth or width of imports 
that I'm running into or something.

Please let me know if there is anything else I can do 
to help replicate this.

Perhaps I'm simply doing something wrong?
msg642 (view) Author: Nobody/Anonymous (nobody) Date: 2004-01-08.21:45:45
Logged In: NO 

I'm having similar problems using the xml.* libraries.  Sounds 
like the same problem?

Having trouble with package imports in jythonc, both jython 2.
1 and 2.2a0.  I've found various other people complaining of 
similar issues, but haven't seen a good resolution - is it an 
unavoidable issue?

Simplest case I've found is this two-liner, foo.py:

from xml.sax.drivers2.drv_xmlproc import create_parser
print create_parser()

After jythonc via:

d:/jython2-1a/jythonc --compiler c:/j2sdk1.4.2_03/bin/javac.
exe --deep --jar foo.jar foo.py

and run via:

c:/j2sdk1.4.2_03/bin/java -cp ./foo.jar;d:/jython2-1a/jython.
jar foo

it reports:

ImportError: cannot import name xmlval

If you use the slight variation:

from xml.sax.drivers2 import drv_xmlproc
print drv_xmlproc.create_parser()

you get:

ImportError: cannot import name drv_xmlproc
msg4266 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2009-03-13.23:34:21
jythonc is no longer maintained
History
Date User Action Args
2009-03-13 23:34:21fwierzbickisetstatus: open -> closed
resolution: wont fix
messages: + msg4266
nosy: + fwierzbicki
2002-04-11 08:09:19juucreate