jython import search path

Diez B. Roggisch deets at nospam.web.de
Thu Feb 22 04:58:32 EST 2007


Russ wrote:

> On Feb 21, 4:15 pm, Larry Bates <lba... at websafe.com> wrote:
>> Russ wrote:
>> > I have a Python program that I want to run in Jython so I can get Java
>> > bytecode output. The program runs fine in Python, but when I change
>> > the first line of the main program to make it run in Jython, it fails
>> > to find some of the imported modules. These are just plain Python
>> > imports of code I wrote myself in another directory.
>>
>> > Apparently Jython does not use the PYTHONPATH environment variable. I
>> > created an environment variable called JYTHONPATH just to see what
>> > would happen, but it didn't work either. How am I supposed to tell
>> > Jython where to search for imported modules? Thanks.
>>
>> Maybe Jython expert has the perfect answer but til then.
>>
>> Did you try:
>>
>> sys.path.append('path to search')
>>
>> Usually this works if nothing else does.
>>
>> -Larry
> 
> Thanks. That's a good workaround, but I would like to know the
> "correct" way to do it too if anyone out there knows.

That is pretty much an accepted strategy. Another one is to alter the
registry file, which has a property python.path. It might even be possible
to use

java -Dpython.path=<whatever>

to accomplish that - but I'm to lazy to toy around now.

Diez



More information about the Python-list mailing list