Trying to import pypyodbc module gives error 'ODBC Library is not found. Is LD_LIBRARY_PATH set?'
Asked Answered
L

2

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?'
Lesotho answered 29/6, 2017 at 13:4 Comment(1)
Note I posted this Q&A after being suggested to do so in my answer to Set LD_LIBRARY_PATH before importing in python.Lesotho
L
12

Installing the python-pyodb package solved it:

sudo apt-get install python-pyodbc

Now the import succeeds:

In [2]: import pypyodbc

In [3]:    
Lesotho answered 29/6, 2017 at 13:4 Comment(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.Godhood
@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!Lesotho
P
0

I was running Python 3.10 in a Debian Dev Container using VS Code.

I had similar errors, but could not install python-pyodbc.

I used the steps recommended in this answer to a similar question from JustLearning (in part because I could not install unixodbc-dev either).

That questoin discusses pyodbc, but I am also trying to use pypyodbc like you.

Running the right steps from Install the Microsoft ODBC driver for SQL Server (Linux) for your operating system and version resolved issues like OSError: libodbc.so: cannot open shared object file: No such file or directory and pypyodbc.OdbcNoLibrary: 'ODBC Library is not found. Is LD_LIBRARY_PATH set?' for me.

Podagra answered 10/7, 2024 at 13:58 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.