title: Why can't macports pyodbc find a data source name or driver on MacOSX (Snow Leopard)?
body: <p>I've installed the mac ports package for py27-odbc on Snow Leopard. Since OSX no longer supplies the ODBC Administrator application, I've installed the OpenLink ODBC manager. After installing, I created a DSN for my remote database, and verified that the configuration works using the iodbctest utility. I then attempt to connect to the database using pyodbc:</p>
  
  <pre><code>import pyodbc
  cnxn = pyodbc.connect('DSN=my-dsn-name;UID=joe;PWD=secret')
  </code></pre>
  
  <p>and I get the following lovely error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name
  not found, and no default driver specified (0) (SQLDriverConnectW)')
  </code></pre>
  
  <p>Why can't pyodbc find the ODBC drivers and/or my DSN configurations?</p>
  
  <p><em>Updated (since I can't answer my own question yet)</em></p>
  
  <p>It appears as if the system stores ODBC configuration data in /Library/ODBC, but the Mac Ports stores configuration in /opt/local/etc. This explains why iodbctest works, but the pyodbc chokes. The cleanest fix seems to be simply symlinking from the Mac Ports location to the system location, so that a common set of configuration files will work for any tool, regardless of where it's looking for this information:</p>
  
  <pre><code>sudo ln -s /Library/ODBC/odbc.ini /opt/local/etc/odbc.ini
  sudo ln -s /Library/ODBC/odbcinst.ini /opt/local/etc/odbcinst.ini
  </code></pre>