1

I am using the Spring boot for an Java application and I want to put a python module my_module.py in the the app. I am trying to import the module like

interpretor.exec("import my_impodule")

But I am getting the error ImportError: No Module named my_module and when I check the current working directory using

interpretor.exec("import os\nprint os.getcwd()")

which gave me the path /my_project/ and my module location is /my_project/my_module.py which is correct. It should pick up the module if current working directory is this.

Can someone please help me where to put the python module so that I can picked up by Jython.

1 Answer 1

1

You need to set the Python module path. So that it can pick your module like this:

Properties pyProperties = new Properties();
pyProperties.put("python.path", System.getProperty("user.dir") + MODULE_PATH);
PythonInterpreter.initialize(System.getProperties(), pyProperties(), new String[0]);
PythonInterpreter pyInterpreter = new PythonInterpreter();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.