RJH2 RJH2 - 3 months ago 17x
Python Question

pyODBC refuses to look for unixODBC, instead looks for iODBC

Is there a way to get pyODBC v3.0.10 to look for the unixODBC driver, instead of the iODBC driver it seems to want to look for?

My understanding is that pyODBC v3.0.10 is supposed to do this by default, while versions prior to v3.0.7 required a manual edit to the setup.py file (see reference here).

One more clue, I ran this code to list my ODBC sources, and it returned nothing:

sources = pyodbc.dataSources()
dsns = list(sources.keys())
sl = []
for dsn in dsns:
sl.append('%s [%s]' % (dsn, sources[dsn]))

Further Background

I have been struggling with creating a connection to MSSQL Server using the following setup: pyODBC --> unixODBC --> FreeTDS --> MS SQL. The gory details are documented here.

I've got it narrowed to a specific issue (I think): the pyODBC package is looking for the iODBC driver instead of the unixODBC driver I've installed and configured. I believe this because when I run:

import pyodbc

'DATABASE= DatabaseName;'

I get this error, with a reference to not finding the iODBC driver:

Error Traceback (most recent call last)
<ipython-input-12-607f0d66e615> in <module>()
1 pyodbc.connect(
----> 2 'DRIVER=FreeTDS;'
3 'SERVER= MyServerIP;'
4 'PORT=1433;'
5 'DATABASE= DatabaseName;'

Error: ('00000', '[00000] [iODBC][Driver Manager]dlopen(FreeTDS, 6): image not found (0) (SQLDriverConnect)')

Thanks for any light you can shed.


I believe the reason is you may have compiled pyodbc to use iODBC (or maybe that's the default). If you want tomake sure you build pyodbc against unixODBC, you can specify that just before running setup.py build, as instructed here (look at http://www.easysoft.com/developer/languages/python/pyodbc.html , headline pyodbc 3.0.x). Alternatively, try to follow the instructions here: https://code.google.com/archive/p/pyodbc/wikis/Building.wiki