> Now I'm running into trouble loading jcc in python, because it can't
> find the JVM dll:
> 
>      from _jcc import initVM
>  ImportError: DLL load failed: The specified module could not be found.
> 
> If I attempt to use jcc to compile Lucene, I get the pop-up box
> saying, "This application has failed to start because jvm.dll was not
> found.  Re-installing the application may fix this problem."

This is kind of nasty.  Turns out I need $JAVAHOME/jre/bin/client on
my PATH before "import jcc" will work in Python.  This is the logical
equivalent of the LD_LIBRARY_PATH problem on Unix.  So, we need to
figure out how to do this for Windows Python.  We really want Python
(rather, the JCC __init__.py file) to look in the Windows registry and
do the right thing with what it finds there (basically, adding the
right location for the jvm.dll to sys.path), before it attempts to
import either "jcc" or "_jcc".

By the way, I'm using setuptools 6c8.  Pretty up-to-date.

Here's some code to pull a value out of the registry:

import _winreg as wreg

class WindowsRegistry:

    # see the Python Cookbook, #146305, Dirk Holtwick

    def __init__(self, keyname):
        """
        handle registry access
        """
        self.reg = wreg.ConnectRegistry(None, wreg.HKEY_LOCAL_MACHINE)
        self.key = wreg.OpenKey(self.reg, keyname)

    def get(self, name):
        " get value out of registry "
        v, t = wreg.QueryValueEx(self.key, name)
        return v, t

    def close(self):
        " close the key finally "
        self.key.Close()
        self.reg.Close()

    def __del__(self):
        self.close()


def get_registry_value (vname, subname):
    r = WindowsRegistry(vname)
    v, t = r.get(subname)
    return v

javaversion = get_registry_value(r"SOFTWARE\JavaSoft\Java Development Kit", 
"CurrentVersion")
javahome = get_registry_value(r"SOFTWARE\JavaSoft\Java Development Kit\%s" % 
javaversion, "JavaHome")


Bill


_______________________________________________
pylucene-dev mailing list
[email protected]
http://lists.osafoundation.org/mailman/listinfo/pylucene-dev

Reply via email to