Open SoulH-qqq opened 7 months ago
It looks like you have a java pacakge called torchvision that is being imported instead of the python package you want. We have a wiki section on naming conflcts that might be helpful. You will probably need to implement a custom ClassEnquirer that prevents the import from java for that package.
Torchvision is an additional package of the PyTorch deep learning framework. There is no java package. I import other packages such as
val newJep = new SharedInterpreter
newJep.exec("from PIL import Image")
The same error will also be reported
Are you using jython in your program? Jtython may be causing problems with the ClassEnquirer.
The stacktrace in you description is only possible if the ClassEnquirer is reporting that torchvision, or PIL, is a java package. In my environment with the default ClassList that is not the case and I am able to import python packages normally in jep. There must be something specific about your environment or the way you are using jep that is causing this problem.
When I run this code it works
val newJep = new SharedInterpreter newJep.exec("from java.lang import System")
But when I run this code, I get an error
val newJep = new SharedInterpreter newJep.exec("from torchvision import transforms")
The error message is as follows:
<class 'ImportError'>: profile.run jep.JepException: <class 'ImportError'>: profile.run at /opt/miniconda3/lib/python3.12/site-packages/jep/java_import_hook.__getattr__(java_import_hook.py:57) at /opt/miniconda3/lib/python3.12/cProfile.<module>(cProfile.py:24) at /opt/miniconda3/lib/python3.12/site-packages/torch/_dynamo/utils.<module>(utils.py:5) at /opt/miniconda3/lib/python3.12/site-packages/torch/_dynamo/allowed_functions.<module>(allowed_functions.py:30) at /opt/miniconda3/lib/python3.12/site-packages/torch/_dynamo/__init__.<module>(__init__.py:2) at /opt/miniconda3/lib/python3.12/site-packages/torchvision/ops/roi_align.<module>(roi_align.py:4) at /opt/miniconda3/lib/python3.12/site-packages/torchvision/ops/poolers.<module>(poolers.py:10) at /opt/miniconda3/lib/python3.12/site-packages/torchvision/ops/__init__.<module>(__init__.py:23) at /opt/miniconda3/lib/python3.12/site-packages/torchvision/models/convnext.<module>(convnext.py:8) at /opt/miniconda3/lib/python3.12/site-packages/torchvision/models/__init__.<module>(__init__.py:2) at /opt/miniconda3/lib/python3.12/site-packages/torchvision/__init__.<module>(__init__.py:6) at <string>.<module>(<string>:1) at jep.Jep.exec(Native Method) at jep.Jep.exec(Jep.java:353)
The torchvision module has already been installed, and there is no problem running the import on the command line.