How to build pyodbc with links to iODBC in macOS?

748 views Asked by At

In Driver for pyodbc: how to specify its location in macOS?, TallTed suggested to open question to explain the following

Build pyodbc with links to iODBC (not its default of UnixODBC, which is not typical for macOS).

so now with the focus —

How can I build pyodbc with links to iODBC (not its default of UnixODBC, which is not typical for macOS)?

1

There are 1 answers

1
DonP On BEST ANSWER

This should/might work in 4.0.23, as it was the way it was done up to pyodbc v3.0.7:

First, in the file setup.py, change line 165 from --

    settings['libraries'].append('odbc')

-- to --

    settings['libraries'].append('iodbc')

Second, disable/delete lines 178, 179, and 183.

        # Add directories for MacPorts and Homebrew.
#       dirs = ['/usr/local/include', '/opt/local/include','~/homebrew/include']
#       settings['include_dirs'].extend(dir for dir in dirs if isdir(dir))

        # unixODBC make/install places libodbc.dylib in /usr/local/lib/ by default
        # ( also OS/X since El Capitan prevents /usr/lib from being accessed )
#       settings['library_dirs'] = [ '/usr/local/lib' ]

For reference, see the file setup.py as of pyodbc 3.0.7, starting at line 146

Note: This will use the macos system supplied -- and presumably outdated -- libiodbc.dylib in /usr/lib. Not sure where the iODBC Framework installs the iODBC files, though. Maybe TallTed can comment on this?