I have a Jython module com.xyz.module1
in Jython site-packages directory. The directory structure is below.
Jython2.7
|---Lib
|--site-packages
|--com
|--__init__.py
|--xyz
|--__init__.py
|--module1
|--__init__.py
When i try to import com.xyz.module1
in Jython interpretor, ImportError
is thrown (screenshot). However, import works fine when i rename com.xyz.module1
to foo.xyz.module1
.
I have read Jython doc which discourages (but does not forbid) the use of com
as top level module namespace. Also the Jython library i am interested in cannot be refactored not to use com
as top level namespace.
Is there any other way to make the import to work?
I don't think so. There is an unresolvable conflict here between the way Python import works and the way people name Java packages.
Perhaps this is overly simplistic, but the first 'com' encountered during import will be the one and only 'com', and will prevent the second 'com' from being imported.
So, you need to take a different approach when naming your Jython (Python) packages.