From: Brian C. <cor...@gm...> - 2006-02-16 13:53:32
|
I've had success with custom python modules by setting the python.pathprope= rty. My jython script now includes : -Dpython.path=3D"$PYTHONPATH" So what ever my PYTHONPATH includes, Jython can also use. I've not tried this with the PythonInterpreter in Java code, but it works when I run jython code from the command line. I would expect that it would work the same. I'm using jython 2.1. --Brian On 2/16/06, Michel Albert <Mic...@st...> wrote: > > Hi, > > After searching through the mailing list archives I have the impression I > am > the only one trying to write some java code and import a custom python > module. Everyone seems to try it directly in python. So here's some code: > > <code> > [...] > public static void main(String[] args) throws PyException { > PythonInterpreter interp =3D new PythonInterpreter(); > > interp.exec("import sys"); > > interp.exec("from rematch.op.StringReplaceOp import *"); > [...] > </code> > > "rematch" is a module I wrote myself and installed it using the standard > python "setup.py" procedure. If I try to import it from whithin the pytho= n > interpreter it works just fine: > > <code> > malbert@stones:~$ python > Python 2.4.2 (#2, Sep 30 2005, 21:19:01) > [GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > All loaded! > ------------------------------------------------------------ > python $ import sys > python $ import rematch > python $ > </code> > > node: don't mind the python prompt. I edited my startup file. Other than > that > it's normal python ;) > > Well all this is good and shiny. But now in jython: > > <code> > malbert@stones:~$ /opt/jython-2.1/jython > Jython 2.1 on java1.5.0_05 (JIT: null) > Type "copyright", "credits" or "license" for more information. > >>> import sys > >>> import rematch > Traceback (innermost last): > File "<console>", line 1, in ? > ImportError: no module named rematch > >>> > </code> > > The module is installed in "/usr/lib/python2.4/site-packages/rematch" the > way > it should be. So why can't jython access it? > > As you can see I installed jython into "/opt". I suppose that's not the > problem or is it? The cache dir is also writeable. Do I have to do > something > about sys.path? And if so how do I do that? > The docs talk a lot about Environment variables and the "registry" file. > But > the explanations are vague at best. > > > |