I've been following the Jython book to be able to get a Java application to import a Python module.
http://www.jython.org/jythonbook/en/1.0/JythonAndJavaIntegration.html#one-to-one-jython-object-factories specifically says "In order to utilize a Jython module using this technique, you must either ensure that the .py module is contained within your sys.path, or hard code the path to the module within your Java code"
How do I ensure that the .py module is added to the sys.path within pydev in Eclipse?. I'm using Eclipse Kepler release Build id: 20130614-0229, Pydev version 2.8.1 and JDK 6.
I keep getting import errors whenever I try to import a Python module.
Printing sys.path from the Java class as in the following snippet tells me that the sys.path is composed of ['C:\jython2.5.3\Lib', 'classpath', 'pyclasspath/'].
How do I set this sys.path in the project properties (or anywhere within the Pydev development environment)?
I do not want to modify sys.path in the Java code?
public BuildingFactory() {
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.exec("import sys");
interpreter.exec("import sys.path");
interpreter.exec("print sys.path");
interpreter.exec("from Building import Building");
buildingClass = interpreter.get("Building");
}
['C:\jython2.5.3\Lib', 'classpath', 'pyclasspath/']
Exception in thread "main" Traceback (most recent call last):
File "", line 1, in
ImportError: No module named Building
UPDATE
Per http://wiki.python.org/jython/JythonFaq/InstallingJython#What_do_.22python.path.22_and_.22python.prepath.22_mean_in_the_Jython_registry.3F, the python.path was modified in the Jython registry file to add the Python module to the pythonpath. Thanks, @SimonC for the hint.