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
How to Get the Last Day of the Month
Accessing Dict Keys Like an Attribute
Python List by Value Not by Reference
Oserror 38 [Errno 38] with Multiprocessing
Run a Python Script in Terminal Without the Python Command
How to Create a User in Linux Using Python
Which Command to Use for Checking Whether Python Is 64Bit or 32Bit
Binding Callbacks to Minimize and Maximize Events in Toplevel Windows
How to Default Python3.8 on My MAC Using Homebrew
Paramiko Error: Error Reading Ssh Protocol Banner
How to Get the Process Name by Pid in Linux Using Python
Why am I Getting Socket.Gaierror: [Errno -2] from Python Httplib
Can't Build Matplotlib (Png Package Issue)
Sharing Psycopg2/Libpq Connections Across Processes
How to Get an Windows Executable from My Kivy App (Pyinstaller)