I'm using jython 2.2 with PyDev.
PyDev is unable to import modules if the paths of imported JARS and the
path to the .py files look similar. E.g.:
Java class Foo resides in a package structure:
Python file resides in
In this case an ImportError is thrown:
ImportError: no module named a.b.x
When I move the python files to another package (e.g.: k.l.m.Foo) the
problem disappear. It looks as if Jython tries to import my .py.class files
from the Java classpath.
I've asked this at the PyDev forum as well, but they pointed out that it's
likely a Jython issue.
From: David Huebel <davidhuebel@gm...> - 2007-09-26 18:35:29
On 9/26/07, Berco Beute <cyberco@...> wrote:
> I'm using jython 2.2 with PyDev.
> PyDev is unable to import modules if the paths of imported JARS and the
> path to the .py files look similar. E.g.:
> Java class Foo resides in a package structure:
> Python file resides in
As I understand it, each module/package must either be a Python module
or a Java package. In the case you describe, a and a.b both have a
dual module/package identity that isn't allowed. Python is more
restrictive compared to Java because Python modules aren't just
abstract groupings of submodules; Python modules can contain actual
code. You can't have two copies of the same Python module with the
same name. I think this is the justification for disallowing the
situation you describe.
For example, in Java, if dir1 and dir2 were both on my classpath, this
would be fine:
There is still only one package com.foo containing two classes, Foo1 and Foo2.
In Python, if dir1 and dir2 were both on my python.path, this would be wrong:
In this case, there are two *different* modules named com.foo, each
containing one class. This isn't allowed. In the case of a Python
module and one or more Java packages sharing the same name, Jython
follows the stricter Python rule and disallows it.
So, bottom line, the unfortunate fact is that Java package naming
conventions are just incompatible with the way Python works. (The
"com" directory would get a wee bit crowded.) On the bright side, if
you stick to the naming conventions of each language when you write in
that language, the odds are that your Python code and Java code will
work together in Jython without a hitch.