Search code examples
pythonnativeeasy-install

Correctly setting LD_LIBRARY_PATH after installing a module with easy_install


I have installed the pyodbc Python module by running easy_install path/to/egg. The module uses native code. The output indicated success.

However when trying to import pyodbc, an error is raised: cannot open shared object file.

Research on this site shows that Python looks for native libraries in the path specified by the environment variable LD_LIBRARY_PATH. So I should set it to point to the path where easy_install has put the native files during installation.

However, I can't find this path. I have looked in /usr/lib, /usr/lib64, and some more directories which made sense (I'm not currently on the Linux machine at work, so I'm sorry I can't remember the additional directories I looked in).

Please explain where this can path be found.


Solution

  • 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)