Import error

314 views
Skip to first unread message

erikj

unread,
Feb 9, 2017, 3:27:16 PM2/9/17
to Jep Project
Hello. I have successfully been using Jep as an embedded python script engine in a Java-based control system for a couple of weeks now. Yesterday I ran into a problem and I cannot figure out what the cause is. In the python code I have the following import statement for a java class:

from atst.wccs.cv.camera import CameraController

This class exists and is in the search path of the python interpreter. I have other java classes in the same tree that are imported with no problem. When Jep tries to load this class I get the following error:

jep.JepException: <class 'ImportError'>: No module named 'atst.wccs.cv.camera'

I have tried everything I can think of to troubleshoot this without any luck. I have even eliminated all shared modules and had the import as the only statement in the python script that is executed. When I google search on "No module named" I come up with a few hits for errors that appear to be unrelated to this issue.

Has anyone encountered a problem like this? Any guidance is appreciated.

Thanks in advance,
Erik

Nathan Jensen

unread,
Feb 10, 2017, 12:09:52 PM2/10/17
to erikj, Jep Project
Hi, the ImportError and "No module named" indicate that it's trying to import the Java class as a Python module.  Otherwise you would get a ClassNotFoundException or an error such as "LoadClass failed".

Jep has an interface ClassEnquirer that is used to determine if it should try to import from Java or Python.  It will try an import from one or the other, not both.  In this case it appears that you have a Java class but the ClassEnquirer determined otherwise and tried to import it from Python.  You can set a ClassEnquirer on a JepConfig object that is then used to initialize the Jep instance.  See the javadoc for more information.

The default ClassEnquirer is a class named ClassList which identifies all the JRE classes and classes from the Java classpath as Java classes, anything else is considered a Python module.  The ClassLoader is also used so if the Java classloader can't see your class, it's likely that it's considered a Python module.

To fix the problem you can debug into ClassList and try to figure out why it doesn't see the class as a Java class, or you can implement your own ClassEnquirer and set that on the JepConfig used to initialize the Jep instance.

--
You received this message because you are subscribed to the Google Groups "Jep Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jep-project+unsubscribe@googlegroups.com.
To post to this group, send email to jep-p...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jep-project/d00a39a6-1e6e-49ac-a219-2649a2f38884%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

erikj

unread,
Feb 13, 2017, 2:50:41 PM2/13/17
to Jep Project, er...@noao.edu
Hi Nathan,

Thanks for your help on this. I did as you suggested and debugged into ClassList. I think that it is only able to "see" classes which the JVM has already loaded. In this case, the java class in question was on the classpath, but it did not show up in the list of packages that ClassList gets from the JVM. Since all our internal classes begin with a known prefix, I modified ClassList.isJavaPackage() to return true if the package name begins with our prefix. That solved the problem and all our classes are loaded properly.

Thanks!
Erik


On Friday, February 10, 2017 at 10:09:52 AM UTC-7, Nathan Jensen wrote:
Hi, the ImportError and "No module named" indicate that it's trying to import the Java class as a Python module.  Otherwise you would get a ClassNotFoundException or an error such as "LoadClass failed".

Jep has an interface ClassEnquirer that is used to determine if it should try to import from Java or Python.  It will try an import from one or the other, not both.  In this case it appears that you have a Java class but the ClassEnquirer determined otherwise and tried to import it from Python.  You can set a ClassEnquirer on a JepConfig object that is then used to initialize the Jep instance.  See the javadoc for more information.

The default ClassEnquirer is a class named ClassList which identifies all the JRE classes and classes from the Java classpath as Java classes, anything else is considered a Python module.  The ClassLoader is also used so if the Java classloader can't see your class, it's likely that it's considered a Python module.

To fix the problem you can debug into ClassList and try to figure out why it doesn't see the class as a Java class, or you can implement your own ClassEnquirer and set that on the JepConfig used to initialize the Jep instance.
On Thu, Feb 9, 2017 at 2:27 PM, erikj <er...@noao.edu> wrote:
Hello. I have successfully been using Jep as an embedded python script engine in a Java-based control system for a couple of weeks now. Yesterday I ran into a problem and I cannot figure out what the cause is. In the python code I have the following import statement for a java class:

from atst.wccs.cv.camera import CameraController

This class exists and is in the search path of the python interpreter. I have other java classes in the same tree that are imported with no problem. When Jep tries to load this class I get the following error:

jep.JepException: <class 'ImportError'>: No module named 'atst.wccs.cv.camera'

I have tried everything I can think of to troubleshoot this without any luck. I have even eliminated all shared modules and had the import as the only statement in the python script that is executed. When I google search on "No module named" I come up with a few hits for errors that appear to be unrelated to this issue.

Has anyone encountered a problem like this? Any guidance is appreciated.

Thanks in advance,
Erik

--
You received this message because you are subscribed to the Google Groups "Jep Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jep-project...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages