Closed cmdoret closed 5 months ago
Hi @cmdoret, it is possible to solve this issue using Python 3.8 or 3.9 instead, because there might be an issue with jpype
in Python 3.10 and later. Also, jpype
should be shipped when installing deeponto
through pip
. I am not sure if the conda version of jpype
can work here.
Thanks @Lawhy, I tried recreating the conda environment from scratch using to python 3.8 (also tried with 3.9), the pip install deeponto
command indeed says:
Successfully installed JPype1-1.5.0 [...] deeponto-0.9.1 [...]
Yet, I still run into the same issue :/
Python 3.8.19 | packaged by conda-forge | (default, Mar 20 2024, 12:47:35)
Type 'copyright', 'credits' or 'license' for more information
IPython 8.12.3 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from deeponto.onto import Ontology
Please enter the maximum memory located to JVM [8g]:
INFO:deeponto:8g maximum memory allocated to JVM.
INFO:deeponto:JVM started successfully.
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 1
----> 1 from deeponto.onto import Ontology
File ~/.local/share/micromamba/envs/deeponto38/lib/python3.8/site-packages/deeponto/onto/__init__.py:14
1 # Copyright 2021 Yuan He. All rights reserved.
2
3 # Licensed under the Apache License, Version 2.0 (the "License");
(...)
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
---> 14 from .ontology import Ontology, OntologyReasoner
15 from .pruning import OntologyPruner
16 from .verbalisation import OntologyVerbaliser, OntologySyntaxParser
File ~/.local/share/micromamba/envs/deeponto38/lib/python3.8/site-packages/deeponto/onto/ontology.py:47
45 from java.io import File # type: ignore
46 from java.lang import Runtime, System # type: ignore
---> 47 from org.slf4j.impl import SimpleLogger # type: ignore
48 System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "warn") # set slf4j default logging level to warning
49 from org.semanticweb.owlapi.apibinding import OWLManager # type: ignore
ModuleNotFoundError: No module named 'org.slf4j'
Do you have any other suggestion?
Hi @cmdoret, it can also be the version of your Java that causes the problem. DeepOnto is using OWL API 4 which requires Java 7 or 8 as the backend. You can also comment line 47 temporarily to see if slf4j
is the package that causes the problem. FYI, my JDK version is as follows:
openjdk version "21.0.2" 2024-01-16
OpenJDK Runtime Environment (build 21.0.2+13-Ubuntu-122.04.1)
OpenJDK 64-Bit Server VM (build 21.0.2+13-Ubuntu-122.04.1, mixed mode, sharing)
Thanks @Lawhy, I tried commenting out that line, but the same error is then raised by the from org.semanticweb.owlapi.apibinding import OWLManager
statement below, which led me to think it was a JPype problem.
Unfortunately, I cannot afford to downgrade java (11) on my machine (required by other software), this dependency would make a strong case for dockerizing deeponto and its dependencies. Did you start / plan anything in that direction, and do you think this would be useful?
Hi @cmdoret, have you also tried to test jpype
alone? It has some default Java imports to play with. Also, please ensure that there is nothing named org
in your paths or Python dependencies, which will override the Java's modules. This happened once before when another person asked me for help. The problem with the Java version might not be the problem as every Java dependency in deeponto
is in JAR
. My development jdk version is quite new as well.
About dockers, it is a good idea but I currently have no time to implement this.
Did you try the statement?
print(jpype.java.lang.System.getProperty('java.class.path'))
If the jar is in the path and the import statement is failing then it may be a conflicting python module. This can be bypassed by placing an alias statement such that some other symbol like "jorg" is used to refer to "org".
Example:
import jpype
import jpype.imports
jpype.imports.registerDomain('mypkg','java') # Someone has foolishly created a "java" directory so we can't import without a conflict
jpype.startJVM()
from mypkg.lang import String # Imports java.lang.String
@Lawhy you were exactly right... I have a folder named ~/org
containing my emacs org-mode notes :/
Removing it solved the issue. It's a very unfortunate limitation, and could be useful to have some kind of warning / error message.
Thanks for your help! :)
@Thrameos thank you, your example worked and help me figure out that the issue was elsewhere :+1:
Describe the bug After following the installation instructions (via conda) of deeponto+pytorch+jpype, I cannot import the
Ontology
class. It seems that allorg.*
packages cannot be imported. Setting and exportingJAVA_HOME
manually does not seem to fix the issue.It fails with the following error (full traceback below):
Any advice would be appreciated.
To Reproduce Steps to reproduce the behavior:
conda create -n deeponto python=3.10
conda activate deeponto
conda install pytorch torchvision torchaudio cpuonly -c pytorch -c conda-forge
conda install -c conda-forge jpype1
from deeponto.onto import Ontology
Expected behavior The
Ontology
is imported.Screenshots Traceback below:
Desktop (please complete the following information):