title: Cannot import pyodbc on Mac
body: <p>I am unable to import <code>pyodbc</code> on my Macbook Pro (running Mac OS X 10.10.5) and python version 2.7.10.  I used <code>pip</code> to get it, and I have the latest version (3.0.10).  It gives me the following error:</p>
  
  <pre><code>$ python
  Python 2.7.10 (default, Jul 14 2015, 19:46:27) 
  [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
  Type "help", "copyright", "credits" or "license" for more information.
  &gt;&gt;&gt; import pyodbc
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  ImportError: dlopen(/Library/Python/2.7/site-packages/pyodbc.so, 2): Symbol not found: _SQLAllocHandle
    Referenced from: /Library/Python/2.7/site-packages/pyodbc.so
    Expected in: flat namespace
   in /Library/Python/2.7/site-packages/pyodbc.so
  </code></pre>
  
  <p>I have tried several things over the past few months to no avail, including building it myself (and (re-)installing <code>iodbc</code> and <code>unixodbc</code> along the way).</p>
  
  <p>One of the weird things is that none of the other python database packages I've tried to use (e.g., sqlalchemy, pypyodbc, etc.) work either for various and similar reasons either.  This has led me to suspect some underlying problem with my ODBC driver or library, but I don't know how to diagnose it.</p>
  
  <p>I am working in a shared code environment where the rest of the team is using <code>pyodbc</code> via Windows and I <em>really</em> need this to work now.  Any help or suggestions would be much appreciated!</p>
  
  <hr>
  
  <p>**Added more details in reply to mauro's answer.  Note, second update below changes things. **</p>
  
  <p>Here are some more details that I should have included in the original question.</p>
  
  <p>First, here are the results of the commands mauro asked about on my machine.  </p>
  
  <pre><code>$ odbc_config --version
  2.3.2
  $ odbc_config --libs
  -L/usr/local/Cellar/unixodbc/2.3.2_1/lib -lodbc
  $ odbc_config --odbcini
  /usr/local/Cellar/unixodbc/2.3.2_1/etc/odbc.ini
  $ odbc_config --odbcinstini
  /usr/local/Cellar/unixodbc/2.3.2_1/etc/odbcinst.ini
  </code></pre>
  
  <p>I was suspicious about the "Cellar" part, so I looked at the paths in mauro's answer and they all seem to point to Cellar (homebrew?) anyway:</p>
  
  <pre><code>$ ls -al /usr/local/etc/*odbc*
  lrwxr-xr-x  1 *****  admin  39 17 Aug 16:57 /usr/local/etc/odbc.ini@ -&gt; ../Cellar/unixodbc/2.3.2_1/etc/odbc.ini
  lrwxr-xr-x  1 *****  admin  43 17 Aug 16:57 /usr/local/etc/odbcinst.ini@ -&gt; ../Cellar/unixodbc/2.3.2_1/etc/odbcinst.ini
  
  $ ls -al /usr/local/etc/odbc*
  lrwxr-xr-x  1 *****  admin  39 17 Aug 16:57 /usr/local/etc/odbc.ini@ -&gt; ../Cellar/unixodbc/2.3.2_1/etc/odbc.ini
  lrwxr-xr-x  1 *****  admin  43 17 Aug 16:57 /usr/local/etc/odbcinst.ini@ -&gt; ../Cellar/unixodbc/2.3.2_1/etc/odbcinst.ini
  1395:Stephens-BlueDot-MacBook-Pro:~/BlueDot/Code/Data Processing Tools} ls -al /usr/local/etc/*odbc*
  lrwxr-xr-x  1 *****  admin  39 17 Aug 16:57 /usr/local/etc/odbc.ini@ -&gt; ../Cellar/unixodbc/2.3.2_1/etc/odbc.ini
  lrwxr-xr-x  1 *****  admin  43 17 Aug 16:57 /usr/local/etc/odbcinst.ini@ -&gt; ../Cellar/unixodbc/2.3.2_1/etc/odbcinst.ini
  1396:Stephens-BlueDot-MacBook-Pro:~/BlueDot/Code/Data Processing Tools} ls -al /usr/local/lib/*odbc*
  lrwxr-xr-x  1 *****  admin  46 17 Aug 16:57 /usr/local/lib/libodbc.2.dylib@ -&gt; ../Cellar/unixodbc/2.3.2_1/lib/libodbc.2.dylib
  lrwxr-xr-x  1 *****  admin  44 17 Aug 16:57 /usr/local/lib/libodbc.dylib@ -&gt; ../Cellar/unixodbc/2.3.2_1/lib/libodbc.dylib
  lrwxr-xr-x  1 *****  admin  48 17 Aug 16:57 /usr/local/lib/libodbccr.2.dylib@ -&gt; ../Cellar/unixodbc/2.3.2_1/lib/libodbccr.2.dylib
  lrwxr-xr-x  1 *****  admin  46 17 Aug 16:57 /usr/local/lib/libodbccr.dylib@ -&gt; ../Cellar/unixodbc/2.3.2_1/lib/libodbccr.dylib
  lrwxr-xr-x  1 *****  admin  50 17 Aug 16:57 /usr/local/lib/libodbcinst.2.dylib@ -&gt; ../Cellar/unixodbc/2.3.2_1/lib/libodbcinst.2.dylib
  lrwxr-xr-x  1 *****  admin  48 17 Aug 16:57 /usr/local/lib/libodbcinst.dylib@ -&gt; ../Cellar/unixodbc/2.3.2_1/lib/libodbcinst.dylib
  lrwxr-xr-x  1 *****  admin  45 17 Aug 16:59 /usr/local/lib/libtdsodbc.0.so@ -&gt; ../Cellar/freetds/0.95.18/lib/libtdsodbc.0.so
  lrwxr-xr-x  1 *****  admin  42 17 Aug 16:59 /usr/local/lib/libtdsodbc.a@ -&gt; ../Cellar/freetds/0.95.18/lib/libtdsodbc.a
  lrwxr-xr-x  1 *****  admin  43 17 Aug 16:59 /usr/local/lib/libtdsodbc.so@ -&gt; ../Cellar/freetds/0.95.18/lib/libtdsodbc.so
  
  /usr/local/lib/tdbcodbc1.0.0:
  total 144
  drwxr-xr-x   5 root  wheel    170 29 Mar  2013 ./
  drwxrwxr-x  44 root  admin   1496 17 Aug 16:59 ../
  -rwxr-xr-x   1 root  wheel  49796 29 Mar  2013 libtdbcodbc1.0.0.dylib*
  -r--r--r--   1 root  wheel    245 29 Mar  2013 pkgIndex.tcl
  -r--r--r--   1 root  wheel  15624 29 Mar  2013 tdbcodbc.tcl
  </code></pre>
  
  <p>I can connect fine to the DNS via <code>tsql</code> (specifics anonymized):</p>
  
  <pre><code>$ tsql -S servername.myserver.com -U me -P mypw -D testdb
  locale is "en_CA.UTF-8"
  locale charset is "UTF-8"
  using default charset "UTF-8"
  Setting testdb as default database in login packet
  1&gt; 
  </code></pre>
  
  <p>But <code>osql</code> and <code>isql</code> both give problems:</p>
  
  <pre><code>$ isql -v MyDSN me mypw
  [S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
  [01000][unixODBC][FreeTDS][SQL Server]Unknown host machine name.
  [ISQL]ERROR: Could not SQLConnect
  </code></pre>
  
  <p>This one gives the most info.  It's finding the DSN entry in my <code>~/.odbc.ini</code> file at least.</p>
  
  <pre><code>$ osql -S MyDSN -U ***** -P ***** 
  checking shared odbc libraries linked to isql for default directories...
  /usr/local/bin/osql: line 53: ldd: command not found
  error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strings: can't open file:  (No such file or directory)
  osql: problem: no potential directory strings in "/usr/local/bin/isql"
  osql: advice: use "osql -I DIR" where DIR unixODBC\'s install prefix e.g. /usr/local
  isql strings are:
  checking odbc.ini files
      reading /Users/*****/.odbc.ini
  [MyDSN] found in /Users/*****/.odbc.ini
  found this section:
      [MyDSN]                                                                                                                
      Description         = testdb SQLServer DB
      Driver              = FreeTDS
      Trace               = Yes
      TraceFile           = /tmp/sql.log
      Database            = Places
      ServerName          = *****
      UserName            = *****
      Password            = *****
      Port                = 1433
      Protocol            = 7.2
      ReadOnly            = No
      RowVersioning       = No
      ShowSystemTables    = No
      ShowOidColumn       = No
      FakeOidIndex        = No
  looking for driver for DSN [*****] in /Users/*****/.odbc.ini
    found driver line: "  Driver              = FreeTDS"
    driver "FreeTDS" found for [*****] in .odbc.ini
  found driver named "FreeTDS"
  "FreeTDS" is not an executable file
  looking for entry named [FreeTDS] in /odbcinst.ini
  grep: /odbcinst.ini: No such file or directory
  </code></pre>
  
  <p>I'm not sure how to fix the problems that <code>isql</code> is reporting, but it seems to indicate that I have something misconfigured to me with odbc.  Unfortunately, I'm sorry that I don't know / remember precisely what I did to get it this way -- I've seriously been trying various things related to this on and off for weeks.</p>
  
  <hr>
  
  <p><strong>Second update after mauro's comments.</strong></p>
  
  <p>I've made a bit of progress.  I reinstalled both unixODBC and freeTDS (directly from <a href="http://www.unixodbc.org/" rel="noreferrer">http://www.unixodbc.org/</a> and <a href="http://www.freetds.org/" rel="noreferrer">http://www.freetds.org/</a> instead of using homebrew), and after doing so the output of my <code>odbc_config</code> commands matched mauro's output. </p>
  
  <p>After some playing with my paths, I then was able to get both <code>osql</code> and <code>isql</code> to successfully connect to my SQL Server instance.  (I discovered one reason this was failing before was because the IT dept. in my organization was blocking all traffic to port 1433 when on the LAN.  When I switched to Wifi, like my Windows co-worker, it worked.)   I consider this great progress!</p>
  
  <p>However, when I tried to import pyodbc from within python again, I got the exact same error message as I started out with.  Sigh.  So any other ideas would still be appreciated!</p>