I've had success with custom python modules by setting the python.path property.
My jython script now includes :


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.


On 2/16/06, Michel Albert <Michel.Albert@statec.etat.lu> wrote:

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:

   public static void main(String[] args) throws PyException {
      PythonInterpreter interp = new PythonInterpreter();

      interp.exec("import sys");

       interp.exec("from rematch.op.StringReplaceOp import *");

"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 python
interpreter it works just fine:

   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 $

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:

   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

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.