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

强颜欢笑 提交于 2019-12-01 02:59:52

问题


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?'

回答1:


Installing the python-pyodb package solved it:

sudo apt-get install python-pyodbc

Now the import succeeds:

In [2]: import pypyodbc

In [3]:    


来源:https://stackoverflow.com/questions/44825966/trying-to-import-pypyodbc-module-gives-error-odbc-library-is-not-found-is-ld-l

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!