|
From: Seshu N. <Ses...@sd...> - 2001-01-04 01:51:49
|
Robert,
Thank you very much for suggesting more than one way to solve this issue.
As you rightly guessed, I moved the jar file elsewhere and .py files in
installed lib directory are not seen by the Interpreter. Copying the lib files
(such as glob.py) into right location solved the problem!
Your code examples are really good to understand the issue.
However, since the glob module doesn't form part of jython.jar, how could this
be supplied to user/customer (not that I'm intending, but just curious to know!)
Thanks,
Seshu
"Robert W. Bill" wrote:
> Seshu Nimmala wrote:
> > Thanks finn. I downloaded the latest jython-2.0b1 and it
> > imports the glob/re modules as stand-alone execution (at
> > command line).
> >
> > However, the glob module still cannot be imported when tried
> > as below in Java code:
> > Is there any special command to be used or something like
> > special setting for PYTHONPATH or someother env
> > variables to be used to run this Java source:
> > Any help will be appreciated.
> > Thanks.
> > __________________________________________
> > import org.python.util.PythonInterpreter;
> > import org.python.core.*;
> > import java.util.*;
> >
> > public class
> > PythonInterpreterTest{
> > PythonInterpreter interp =
> > new PythonInterpreter();
> > public void test() throws PyException {
> > :
> > interp.exec("import glob"); //Cannot import glob here
> > interp.exec("files = glob.glob('*.java')");
> > }
> > }
> > __________________________________________________
>
> Hello Seshu,
> I tried a slightly modified version of your code
> and it worked fine (in jython-2.0b1). Here's what I used:
> ==========================================================
> import org.python.util.PythonInterpreter;
> import org.python.core.*;
>
> public class
> test{
> public static void main(String[] args) throws PyException {
> PythonInterpreter interp =
> new PythonInterpreter();
> interp.exec("import glob");
> interp.exec("files = glob.glob('*.java')");
> interp.exec("print files");
> }
> }
> ===========================================================
> When I run this I get the output:
> ['test.java']
>
> I'm curious what happens when you run something like this:
> ==========================================================
> import org.python.util.PythonInterpreter;
> import org.python.core.*;
>
> public class
> test{
> public static void main(String[] args) throws PyException {
> PythonInterpreter interp =
> new PythonInterpreter();
> interp.exec("import sys");
> interp.exec("print sys.path");
> }
> }
> ===============================================================
>
> For me, I get the following path, which is good because that is where
> glob.py is:
> ['.', '/usr/local/jython-2.0b1/Lib']
>
> This is just a guess, but I suspect that this path will be wrong for
> you. Could you have moved jython.jar out of it's installation
> directory? You can try running your test with-
> "java -Dpython.home=/path/to/jythondir test"
>
> You can guaruntee that this path is correct by initializing a sys.path
> list in your java file. This example is from Finn Bock (tnx Finn for
> your amazing work)-
>
> Properties props = new Properties();
> props.setProperty("python.path", "/home/modules:scripts");
> PySystemState.initialize(System.getProperties(), props,
> new String[] {""});
>
> The value for python.path must follow the operating system conventions
> for the PATH environment var (':' separator for unix, ';' for windows)
>
> regards,
> Robert
|