Trying to Import Pypyodbc Module Gives Error 'Odbc Library Is Not Found. Is Ld_Library_Path Set'

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

Installing the python-pyodb package solved it:

sudo apt-get install python-pyodbc

Now the import succeeds:

In [2]: import pypyodbc

In [3]:

Set LD_LIBRARY_PATH before importing in python

UPDATE: see the EDIT below.

I would use:

import os

os.environ['LD_LIBRARY_PATH'] = os.getcwd() # or whatever path you want

This sets the LD_LIBRARY_PATH environment variable for the duration/lifetime of the execution of the current process only.

EDIT: it looks like this needs to be set before starting Python: Changing LD_LIBRARY_PATH at runtime for ctypes

So I'd suggest going with a wrapper .sh (or .py if you insist) script. Also, as @chepner pointed out, you might want to consider installing your .so files in a standard location (within the virtualenv).

See also Setting LD_LIBRARY_PATH from inside Python

Correctly setting LD_LIBRARY_PATH after installing a module with easy_install

As explained here:

you must set your LD_LIBRARY_PATH to LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib (in your .profile or .bashrc or .zshrc) which points to where the unixodbc and freetds shared libraries got installed if you installed them via your system's package manager.

i.e. if you are on ubuntu, type apt-get install freedts unixodbc

pyodbc is just a wrapper around the C library, hence this requirements.

One last but important thing, after setting your LD_LIBRARY_PATH in one of these environment files, do either colose and reopen your terminal's shell or for example source ~/.bashrc (if you had put this in your bashrc obviously)



Related Topics



Leave a reply



Submit