8

I am running Python 3.5 on my Linux Mint 18. I want to load the pypyodbc module. However, no matter what I try, I always get the error:

OdbcNoLibrary: 'ODBC Library is not found. Is LD_LIBRARY_PATH set?'

In Set LD_LIBRARY_PATH before importing in python I got the suggestion to set the path to os.getcwd(), but it did not work either and gave me the same error.

What should I install to make it work?

See the complete log of the error:

In [1]: import pypyodbc
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
/home/me/env/lib/python3.5/site-packages/pypyodbc.py in <module>()
    426         # First try direct loading libodbc.so
--> 427         ODBC_API = ctypes.cdll.LoadLibrary('libodbc.so')
    428     except:

/usr/lib/python3.5/ctypes/__init__.py in LoadLibrary(self, name)
    424     def LoadLibrary(self, name):
--> 425         return self._dlltype(name)
    426 

/usr/lib/python3.5/ctypes/__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error)
    346         if handle is None:
--> 347             self._handle = _dlopen(self._name, mode)
    348         else:

OSError: libodbc.so: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

OdbcNoLibrary                             Traceback (most recent call last)
<ipython-input-1-8f9e32dd2219> in <module>()
----> 1 import pypyodbc

/home/me/env/lib/python3.5/site-packages/pypyodbc.py in <module>()
    437             lib_paths = [path for path in lib_paths if os.path.exists(path)]
    438             if len(lib_paths) == 0 :
--> 439                 raise OdbcNoLibrary('ODBC Library is not found. Is LD_LIBRARY_PATH set?')
    440             else:
    441                 library = lib_paths[0]

OdbcNoLibrary: 'ODBC Library is not found. Is LD_LIBRARY_PATH set?'
fedorqui
  • 275,237
  • 103
  • 548
  • 598
  • Note I posted this Q&A after being suggested to do so in [my answer](https://stackoverflow.com/a/40976756/1983854) to _Set LD_LIBRARY_PATH before importing in python_. – fedorqui Jun 29 '17 at 13:05

1 Answers1

12

Installing the python-pyodb package solved it:

sudo apt-get install python-pyodbc

Now the import succeeds:

In [2]: import pypyodbc

In [3]:    
fedorqui
  • 275,237
  • 103
  • 548
  • 598
  • 2
    You don't really need `python-pyodbc`, just one of its dependencies. `sudo apt-get install unixodbc` is sufficient to avoid the `pypyodbc.OdbcNoLibrary` error. – Gord Thompson Jun 30 '17 at 12:29
  • @GordThompson this is good to know. I cannot replicate this now, but I will as soon as possible and come back to update if it works fine. Thanks for the heads-up! – fedorqui Jul 03 '17 at 09:15