2

I'm trying to connect to my local postgres database via pyodbc(i'd like to use MySQL workbench to import/view a postgres schema eventually), and I can't seem to get anything to find my psqlodbc driver. I've brew install psqlodbc, and I have the Driver and Setup files, /usr/local/lib/psqlodbcw.so and /usr/local/lib/psqlodbca.so, respectively.

Using the pyodbc library in python, I've tried to connect, but pyodbc can't find my driver

conn_str = (
    "DRIVER={psqlodbc};"
    "DATABASE=postgres;"
    "UID=postgres;"
    "PWD=postgres;"
    "SERVER=localhost;"
    "PORT=5432;"
    )
conn = pyodbc.connect(conn_str)


pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'psqlodbc' : file not found (0) (SQLDriverConnect)")

My ~/.odbc.ini looks like:

1 [PostgreSQL]
2 Description    = PostgreSQL driver for Unix
3 Driver         = /usr/local/lib/psqlodbcw.so
4 Setup          = /usr/local/lib/psqlodbca.so

El Capitan version 10.11 and i get:

file /usr/local/lib/psqlodbcw.so
/usr/local/lib/psqlodbcw.so: Mach-O 64-bit bundle x86_64
file /usr/local/lib/psqlodbca.so 
/usr/local/lib/psqlodbca.so: Mach-O 64-bit bundle x86_64

Not sure what I should do from here. Could this be a configuration or symlink issue?

heliotrope
  • 349
  • 2
  • 17
  • 4
    Driver definitions belong in odbcinst.ini, not odbc.ini. odbc.ini is for defining DSN entries. Also, you'll need to use the driver name you've defined (`DRIVER=PostgreSQL`). – Gord Thompson Jun 02 '17 at 21:15
  • 2
    In addition, the "w" and "a" at the end of the file names almost certainly refer to the [Unicode ("w" for "wide") and ANSI ("a") versions of the driver](https://odbc.postgresql.org/faq.html#2.5). The convention for setup files is that their name ends in "S". – Gord Thompson Jun 02 '17 at 21:29
  • thanks for the help. I've got pyodbc working now. – heliotrope Jun 02 '17 at 22:11

0 Answers0