Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I'm having weird issues with pyodbc and I *think* it's because of odbc_config #164

Open
guymatz opened this issue Mar 17, 2024 · 8 comments

Comments

@guymatz
Copy link

guymatz commented Mar 17, 2024

pyodbc is complaining that it can't find my libs, but strace tells me that it can, but it can't find libodbcinst . . .

odbc_config --libs returns -L/path/to/libs -lodbc . . . should it return -L/path/to/libs -lodbc -lodbcinst?

@lurcher
Copy link
Owner

lurcher commented Mar 17, 2024 via email

@guymatz
Copy link
Author

guymatz commented Mar 17, 2024

Thanks so much for the reply!!

ldd pyodbc.cpython-37m-x86_64-linux-gnu.so  | grep odbc
        libodbc.so.2 => /opt/sw/lib64/libodbc.so.2 (0x00007f960f301000)

pyodbc works when I have LD_LIBRARY_PATH set to the dir of libodbc & friends . . . . it seems that the only difference between when I have LD_LIBRARY_PATH set and when I don't - I.e., when pyodbc works and doesn't - is that libodbcinst is found when LD_LIBRARY_PATH is set:
open("/opt/sw/lib64/libodbcinst.so.2", O_RDONLY|O_CLOEXEC) = 3

When LD_LIBRARY_PATH is not set, pyodbc fails with
pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib '
/opt/sw/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1' : file not found (0) (SQLDriverConnect)")

However strace is telling me that libmsodbcsql is available (not-works.out & works.out are strace output files):
$ grep libmsodbcsql-18 not-works.out works.out
not-works.out:write(1, "conn str: DRIVER={/opt/bb/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1};SERVER=XXX,XXX;DATABASE=XXX;UID=XXX;PWD=XXX;Encrypt=yes;TrustServerCertificate=yes\n", 186) = 186
not-works.out:open("/opt/bb/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1", O_RDONLY|O_CLOEXEC) = 3
not-works.out:open("/opt/bb/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1", O_RDONLY|O_CLOEXEC) = 3
not-works.out:write(2, "pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib '/opt/sw/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1' : file not found (0) (SQLDriverConnect)")\n", 179) = 179

works.out:write(1, "conn str: DRIVER={/opt/sw/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1};SERVER=XXX,XXX;DATABASE=XXX;UID=XXX;PWD=XXX;Encrypt=yes;TrustServerCertificate=yes\n", 186) = 186
works.out:open("/opt/sw/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1", O_RDONLY|O_CLOEXEC) = 3

And I see this sort of thing in strace:
open("/lib64/tls/x86_64/libodbcinst.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/lib64/tls/libodbcinst.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/lib64/x86_64/libodbcinst.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/lib64/libodbcinst.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib64/tls/x86_64/libodbcinst.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib64/tls/libodbcinst.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)

Am I barking up the wrong tree here, thinking the problem is with libodbcinst? I feel like line 1186 of DriverManager/SQLConnect.c is lying to me - that the underlying problem is with finding libodbcinst - but my C is not good enough to figure out what's going on there.

Thank you soooooo much!

@lurcher
Copy link
Owner

lurcher commented Mar 17, 2024 via email

@guymatz
Copy link
Author

guymatz commented Mar 17, 2024

Ahhh!!!!
/opt/bb/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1
linux-vdso.so.1 => (0x00007ffd1cd91000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f33b3987000)
librt.so.1 => /lib64/librt.so.1 (0x00007f33b377f000)
libodbcinst.so.2 => not found
libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007f33b3496000)
libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007f33b3249000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f33b2f41000)
libm.so.6 => /lib64/libm.so.6 (0x00007f33b2c3f000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f33b2a29000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f33b280d000)
libc.so.6 => /lib64/libc.so.6 (0x00007f33b243f000)
/lib64/ld-linux-x86-64.so.2 (0x00007f33b3f9b000)
libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007f33b220c000)
libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007f33b2008000)
libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007f33b1df8000)
libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007f33b1bf4000)
libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f33b19da000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f33b17b3000)
libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f33b1551000)

Thank you!!!!! I guess I'll have to talk to the people who packaged msodbcsql18 . . . any further advice?
Thanks again!

@lurcher
Copy link
Owner

lurcher commented Mar 17, 2024 via email

@guymatz
Copy link
Author

guymatz commented Mar 18, 2024

Thanks again. Last question! Do you know if there is a way around requiring libodbcinst? Some env var I can set (besides LD_LIBRARY_PATH, which needs to be set before I start python, which I'm trying to avoid, because I don't want a wrapper script)? Or something I can set in my connection string? I'll do anything to avoid a wrapper script!!

P.S. - My SAs don't want to help, including either adding to ld.so.conf or mv'ing the lib :-(

@v-chojas
Copy link
Contributor

You can set environment variables from within the python too. https://docs.python.org/3/library/os.html#os.environ

@guymatz
Copy link
Author

guymatz commented Mar 18, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants