Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jep.JepException: <class 'ImportError'>: profile.run #521

Open
SoulH-qqq opened this issue Mar 6, 2024 · 3 comments
Open

jep.JepException: <class 'ImportError'>: profile.run #521

SoulH-qqq opened this issue Mar 6, 2024 · 3 comments

Comments

@SoulH-qqq
Copy link

SoulH-qqq commented Mar 6, 2024

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.

@bsteffensmeier
Copy link
Member

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.

@SoulH-qqq
Copy link
Author

SoulH-qqq commented Mar 6, 2024

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

@bsteffensmeier
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants