From: Kent J. <ke...@td...> - 2006-02-16 14:21:13
|
Michel Albert wrote: > "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: > > 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? Jython is not CPython and doesn't share its libraries. You have to put rematch in the sys.path that Jython sees. Print sys.path from Jython to see the default path. I usually put all the files I need in the working directory, that is always on Jython's sys.path. You can also define the Java system property python.path on the command line with -Dpython.path=whatever or append to sys.path at runtime from Java (PySystemState.path) or Jython (sys.path). Setting python.path to be the same path used by CPython seems like a bad idea to me, many CPython modules will not work with Jython. Kent > > 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. |