Issue1810514

classification
Title: can not import python module begin with com, org
Type: Severity: normal
Components: None Versions:
Milestone:
process
Status: closed Resolution: invalid
Dependencies: Superseder:
Assigned To: Nosy List: cgroves, liaoya
Priority: normal Keywords:

Created on 2007-10-10.02:08:15 by liaoya, last changed 2007-10-11.06:20:03 by cgroves.

Files
File name Uploaded Description Edit Remove
importerror.zip liaoya, 2007-10-10.02:08:16 Demo module for import testing
Messages
msg1967 (view) Author: liaoya (liaoya) Date: 2007-10-10.02:08:15
The jython.bat interactive mode can not import the python module which name begin com or org.

Please delete cachedir under JYTHON directory before each test. I find if the module is imported successfully, the import error will not appear again.

I put three different module in the attachment, they are
com.ssc.sstz.const, oeg.ssc.sstz.const, peg.ssc.sstz.const

ATTENTION: Delete cachedir
If you run with jython.bat under JYTHON directory and enter interactive mode run the command below
----------------------------------------
import sys
sys.path.append(r"C:\HShen\workspace\Europa\JythonDemo\src")   # change the module path to your uncompress directory
print sys.path
import com.ssc.sstz.const
import org.ssc.sstz.const
import peg.ssc.sstz.const

print com.ssc.sstz.const.CONST
print org.ssc.sstz.const.CONST
print peg.ssc.sstz.const.CONST
-----------------------------------------
Then you will find import com.ssc.sstz.const and org.ssc.sstz.const fail, and peg.ssc.sstz.const success

And I find if I put python module in the front of sys.path, It's OK.

ATTENTION: Delete cachedir
If you run with jython.bat under JYTHON directory and enter interactive mode run the command below
----------------------------------------
import sys
sys.path.insert(0, r"C:\HShen\workspace\Europa\JythonDemo\src")   # change the module path to your uncompress directory
print sys.path
import com.ssc.sstz.const
import org.ssc.sstz.const
import peg.ssc.sstz.const

print com.ssc.sstz.const.CONST
print org.ssc.sstz.const.CONST
print peg.ssc.sstz.const.CONST
-----------------------------------------
All the three module are imported successfully.

And I find this problem appear win the jython.bat interactive mode or you run the python script JYTHON HOME directory.
msg1968 (view) Author: liaoya (liaoya) Date: 2007-10-10.02:30:25
This problem exists in jython 2.2 jython 2.2.1rc2. My JDK is sun jdk 1.5.0_12-b04
msg1969 (view) Author: Charlie Groves (cgroves) Date: 2007-10-11.06:20:03
This is because the '__classpath__' entry is used by Jython to decide when to load import Java classes.  If you want to import com and org Python packages, they'll need to be before __classpath__ in sys.path since Java includes classes in com and org Java packages by default.  Jython itself includes com and org Java packages.  It's going to be difficult to get much use out of the Java capabilities of Jython if you have Python code in com or org since most of the interesting Java code lives in those packages as well.
History
Date User Action Args
2007-10-10 02:08:15liaoyacreate