13

I am having a python application that uses mssql - instead of using pymssql, i was trying pyodbc. There seems to be no problems while running the application in a Windows local machine. While deploying the application in a dev env packaged as a container, I see the following errors.

from pyodbc import Error
2017-04-14T13:58:28.858638588Z ImportError: Error loading shared library libodbc.so.2: No such file or directory (needed by /usr/local/lib/python3.5/site-packages/pyodbc.cpython-35m-x86_64-linux-gnu.so)

The docs require me to install the database drivers along with pyodbc.

initial check looks good to me - images shared object dependencies and sym links

Lakshmi Narayanan
  • 151
  • 1
  • 1
  • 8
  • Your container does not have the required ODBC support files installed. For example, in a Ubuntu Linux environment you would need to `sudo apt install unixodbc-dev` to get the missing file(s). – Gord Thompson Apr 15 '17 at 12:28
  • @GordThompson - i have unixodbc-dev installed as well. the confusing part is i see this when I ssh into the container -- /usr/lib/x86_64-linux-gnu/libodbc.so.2 , which i assume is the correct path – Lakshmi Narayanan Apr 17 '17 at 16:00
  • That looks right. When I do `ldd pyodbc.cpython-35m-i386-linux-gnu.so`, one of the lines is `libodbc.so.2 => /usr/lib/i386-linux-gnu/libodbc.so.2 (0xb7670000)`, which is the equivalent location on a 32-bit install of Xubuntu. However, `libodbc.so.2` is a symlink to the actual file `libodbc.so.2.0.0` in the same directory. Have you verified that your `libodbc.so.2` symlink is valid? – Gord Thompson Apr 17 '17 at 16:30
  • Yes. exact same thing. let me add those details in the question itself – Lakshmi Narayanan Apr 17 '17 at 18:47

2 Answers2

21

The ubuntu environment is not having the odbc library, so it need to be installed using

sudo apt install unixodbc-dev 

once installed update the ubuntu using

sudo apt-get update

It will resolve the issue.

For further reading go to this link

neel
  • 572
  • 4
  • 17
-1

With pyodbc, it has lot of issues as you need to download compatible drivers that can be very messy. Instead use pymssql, it doesn't need additional drivers.

For more details : pymssql versus pyodbc versus adodbapi versus...

For sample code : https://pythonhosted.org/pymssql/pymssql_examples.html

Dharman
  • 30,962
  • 25
  • 85
  • 135
mayank584
  • 19
  • 2