swstephe / py2jdbc

Python JDBC Connector
MIT No Attribution
11 stars 0 forks source link

Is the library OS independent? #2

Open envas opened 5 years ago

envas commented 5 years ago

Makes me wonder if anybody could successfully run the library on Windows or macOS?

On Windows, I get the error

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    import py2jdbc
  File "C:\Users\robert\AppData\Local\Programs\Python\Python37\lib\site-packages\py2jdbc\__init__.py", line 2, in <module>
    from py2jdbc.dbi import (
  File "C:\Users\robert\AppData\Local\Programs\Python\Python37\lib\site-packages\py2jdbc\dbi.py", line 6, in <module>
    from py2jdbc.wrap import get_env
  File "C:\Users\robert\AppData\Local\Programs\Python\Python37\lib\site-packages\py2jdbc\wrap.py", line 4, in <module>
    import py2jdbc.jni
  File "C:\Users\robert\AppData\Local\Programs\Python\Python37\lib\site-packages\py2jdbc\jni.py", line 2765, in <module>
    signal.signal(signal.SIGHUP, signal_handler)
AttributeError: module 'signal' has no attribute 'SIGHUP'

which is right, because Windows does not know SIGHUP.

Om macOS I get the error

Traceback (most recent call last):
  File "test.py", line 2, in <module>
    import py2jdbc
  File "/usr/local/lib/python3.7/site-packages/py2jdbc/__init__.py", line 2, in <module>
    from py2jdbc.dbi import (
  File "/usr/local/lib/python3.7/site-packages/py2jdbc/dbi.py", line 6, in <module>
    from py2jdbc.wrap import get_env
  File "/usr/local/lib/python3.7/site-packages/py2jdbc/wrap.py", line 4, in <module>
    import py2jdbc.jni
  File "/usr/local/lib/python3.7/site-packages/py2jdbc/jni.py", line 2620, in <module>
    libjvm.JNI_GetDefaultJavaVMInitArgs.retval = jint
  File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ctypes/__init__.py", line 377, in __getattr__
    func = self.__getitem__(name)
  File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ctypes/__init__.py", line 382, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: dlsym(RTLD_DEFAULT, JNI_GetDefaultJavaVMInitArgs): symbol not found

I checked the libjvm.dylib and the symbol is there.

Any idea?

swstephe commented 5 years ago

I tried to make it independent, but I've been mostly working from Linux. The Windows one is a bug which I can fix. I'll log it as an issue.

I don't have any Mac's I can try the second one, but that symbol looks familiar. I this I encountered it on some older versions of Java JDK and the JNI. You could try setting JAVA_HOME to a more recent version of Java JDK to see if it gets further.

swstephe commented 5 years ago

Okay, I think I got rid of the problems in Windows and did some changes to support Python 2.7 a bit better. Give v0.0.5 a try under Windows.

envas commented 5 years ago

looks fine, I can commit the Windows error is gone.

I have still a problem to find the right JVM. Looking at the jvm.find_libjvm() code the search order is IMO wrong. First, the ctypes utility searches for a JVM library. Obviously, it finds always the first installed Java, so the later calls for PY2JDBC_JAVA_HOME and JAVA_HOME environment searches are meaningless, it cannot override the system LD_LIBRARY_PATH.

In my case, the path found by find_libjvm always points to IBM Java 1.7 regardless of the JAVA_HOME or PY2JDBC_JAVA_HOME setting. Moving ctypes utility search after the JAVA_HOME tries solved the problem.