I've just started using the PythonInterpreter
from within my Java classes, and it works great! However, if I try to include python modules (re
, HTMLParser
, etc.), I'm receiving the following exception (for re
):
Exception in thread "main" Traceback (innermost last): File "", line 1, in ? ImportError: no module named re
How could I make the classes from the jython jar "see" the modules python has available?
You embed jython and you will use some Python-Modules somewere:
if you want to set the path (sys.path) in your Java-Code :
Py is in org.python.core.
rootPath and modulesDir is where YOU want !
let rootPath point where you located the standard-jython-lib
Have a look at src/org/python/util/PyServlet.java in the Jython-Source-Code for example
Check your jython sys.path . Make sure that the library you want to load are in this path. Look at jython faq for more details.
According to the FAQ:
In other words, you can directly use Python modules from Jython, unless you're trying to use built-in modules, in which case you're stuck with whatever has been ported to Jython.
You can refer here for the solution Importing python modules in jython
Download
ez_setup.py
from here http://peak.telecommunity.com/dist/ez_setup.pyThen run
jython ez_setup.py <any module name>
.Running it on any folder path doesn't matter.
I could install pymysql with it, no problem.