|
From: <bc...@wo...> - 2001-03-28 08:59:45
|
On Wed, 28 Mar 2001 17:01:00 +1000, you wrote:
>Hi guys! I am trying to embed Jython in a large multi-tier Java app. I am
>trying to figure out what I have to do to get it to pick up the python.path
>setting from the registry. What I have done so far is:
>
> * change the registry to say:
>python.path = f:\\jython-2.1a1\\lib
> * the registry is f:\jython-2.1a1\registry
> * pass -Dpython.home=f:\jython-2.1a1 as a command line arg to the app
> * instantiate a PythonInterpreter
> * put my library, "minestar_admin.py" into f:\jython-2.1a1\lib.
>
>Now, my theory on how it should work is that when I instantiate
>PythonInterpreter it looks in the system properties for the python.home
>setting. Then it looks in that directory for the file 'registry'. Then it
>loads that file, giving it a value for python.path. Then it looks along
>that path to resolve things.
Yep, that should work.
>However, when I exec the line
>
>import minestar_admin
>
>I get:
>
>Traceback (innermost last):
> File "<string>", line 1, in ?
>NameError: minestar_admin
>
>..
>
>which suggests to me that PythonInterpreter can't find the file.
Failing to find the .py file should result in an
ImportError: no module named...
I think the NameError is a different problem, but you can check your
actual python.path by inserting
interp.exec("import sys; print sys.prefix, sys.path");
If you still can get a handle on the problem, try to make a small
standalone example that show the bug and post it here. This worked for
me:
----------- i:\\temp\\ss9\\registry -----------
python.path=i:\\temp\\ss9\\subdir
----------- i:\\temp\\ss9\\subdir\\minestar_admin.py -----------
print "hello"
----------- si7.java -----------
import org.python.core.*;
import org.python.util.*;
public class si7 {
public static void main(String[] args) {
PythonInterpreter interp = new PythonInterpreter();
interp.exec("import sys; print sys.prefix, sys.path");
interp.exec("import minestar_admin");
}
}
----------- command line -----------
java -Dpython.home=i:\temp\ss9 si7
>Could
>someone please tell me what is wrong with my hypothesis above?
Just for your info, you can also set the python.path property this way:
http://jython.sourceforge.net/cgi-bin/faqw.py?req=show&file=faq06.002.htp
regards,
finn
|