On Mon, Nov 14, 2011 at 4:25 AM, Andi Vajda <[email protected]> wrote:
>
> On Sun, 13 Nov 2011, Roman Chyla wrote:
>
>> I am using JCC to run Python inside Java. For unittest, I'd like to
>> set PYTHONPATH environment variable programmatically. I can change env
>> vars inside Java (using
>>
>> http://stackoverflow.com/questions/318239/how-do-i-set-environment-variables-from-java)
>> and System.getenv("PYTHONPATH") shows correct values
>>
>> However, I am still getting "ImportError: no module named...."
>>
>> If I set PYTHONPATH before starting unittest, it works fine
>>
>> Is it possible what I would like to do?
>
> Why mess with the environment instead of setting sys.path directly instead ?

That would be great, but I don't know how. I am doing roughly this:

PythonVM.start(programName)
vm = PythonVM.get()
vm.instantiate(moduleName, className);

I tried also:
PythonVM.start(programName, new String[]{"-c", "import
sys;sys.path.insert(0, \'/dvt/workspace/montysolr/src/python\'"});

it is failing on vm.instantiate.... when Python cannot find the module

>
>> Alternatively, if JCC could execute/eval python string, I could set
>> sys.argv that way
>
> I'm not sure what you mean here but JCC's Java PythonVM.init() method takes
> an array of strings that is fed into sys.argv. See _PythonVM_Init() sources
> in jcc.cpp for details.

sorry, i meant sys.path, not sys.argv

roman

>
> Andi..
>

Reply via email to