[pylucene-dev] building JCC on Windows with MinGW
Andi Vajda
vajda at osafoundation.org
Wed Mar 19 21:36:31 PDT 2008
On Wed, 19 Mar 2008, Bill Janssen wrote:
>> It's not sys.path (that's where PYTHONPATH ends up), it's the env's PATH or,
>> more precisely, the process's executable search path that needs to be
>> updated. I don't know of a linker way to do this on Windows. Once the
>> process has started, my understanding is that it's too late already.
>
> Right. On Windows, though, this works:
I haven't tried this but it seems to be missing stuff on the Path.
I see you're adding %javahome%/bin/client to Path but what about
%javahome%/bin ? It contains some other needed library. Maybe jvm.dll knows
how to find the rest ? Maybe there is no 'rest' to find ?
If I were to include this into JCC, I'd probably rewrite it in C++ so as to
not depend on the optional winreg module and add a simple call to this in
__init__.py instead. Also, this trick has to be made optional to not be in
the way of more exotic setups such as people with multiple installs of
various JREs, etc, etc...
I guess, I should rewrite this to attempt loading jvm.dll and only play the
Path trick if that call fails. Ok, food for thought :)
Andi..
>
> Index: jcc/jcc/__init__.py
> ===================================================================
> --- jcc/jcc/__init__.py (revision 405)
> +++ jcc/jcc/__init__.py (working copy)
> @@ -22,8 +22,24 @@
>
> # jcc package
>
> +import sys
> +if sys.platform == 'win32':
> +
> + # figure out where the jvm.dll is, and make sure that location is on PATH
> + import _winreg as wreg
> + registry = wreg.ConnectRegistry(None, wreg.HKEY_LOCAL_MACHINE)
> + key = wreg.OpenKey(registry, r"SOFTWARE\JavaSoft\Java Runtime Environment")
> + v, t = wreg.QueryValueEx(key, "CurrentVersion")
> + key = wreg.OpenKey(registry, r"SOFTWARE\JavaSoft\Java Runtime Environment\%s" % v)
> + javahome, t = wreg.QueryValueEx(key, "JavaHome")
> + registry.Close()
> + # if we have a javahome, make sure it's on the PATH
> + if javahome:
> + import os
> + location = os.path.join(javahome, "bin", "client")
> + os.environ['Path'] = ';'.join(os.environ['Path'].split(';') + [location,])
> +
> if __name__ == '__main__':
> - import sys
> from jcc import cpp
> cpp.jcc(sys.argv)
> else:
>
>
> The downside is that you have to add this kind of little startup blit
> to each JCC-wrapped module. So, this either needs to be turned into
> a JCC utility function which gets called once per Python instantiation,
> or generated by the wrapper generation process for each module.
>
> Bill
>
More information about the pylucene-dev
mailing list