Reputation: 2668
When running pip install pyodbc
, I get
In file included from .../build/pyodbc/src/buffer.cpp:12:
.../build/pyodbc/src/pyodbc.h:52:10: fatal error: 'sql.h' file not found
#include <sql.h>
^
1 error generated.
error: command 'cc' failed with exit status 1
It seems that Mavericks has no sql.h under /usr/include
Did anyone manage to install pyodbc? Is there a known workaround?
Upvotes: 38
Views: 37408
Reputation: 885
As pip
doesn't support --no-install
option anymore and the --download
option is deprecated. I had to follow the following steps.
pip download pyodbc
tar -zxvf pyodbc-4.0.17.tar.gz
python setup.py build_ext --include-dirs=[DIRECTORY CONTAINING THE HEADERS]
pip install pyodbc
Upvotes: 0
Reputation: 1
OS Version: El Capitan 10.11.6 Python Version: 2.7.11 Pip Version: pip 9.0.1
1. Install iodbc for Mac (my installation is in [iODB_loc]=/usr/local/iODBC)
2. pip install --download [download_location] pyodbc==3.0.10
3. cd [download_location]
4. tar -xvzf pyodbc-3.0.10.tar.gz
5. cd pyodbc-3.0.10
6. vim setup.py:
settings['libraries'].append('odbc')
->
settings['libraries'].append('iodbc')
7. python setup.py build_ext --include-dirs=[iODB_loc]/include/
8. pip install --upgrade .
Upvotes: -1
Reputation: 12204
I'll add my $0.02 to this. Vitaly's answer was the main inspiration.
OSX 10.9.5, MacPorts 2.3.4, pip 8.1.2 (which did not have an --no-install option), virtualenv 14.0.6
Also helped: https://stackoverflow.com/a/22942120/1394353
Anyway, install iODBC via MacPorts
sudo port install libiodbc
The missing sql.h is deposited by MacPorts @ /opt/local/include
Now, tell pip where it can find the includes (that's where the linked answer came in handy):
pip install pyodbc --global-option=build_ext --global-option="-I/opt/local/include/"
Upvotes: 0
Reputation: 29
I met the the same problem today on ubuntu 14.04. I found some guy in below link said should install unixodbc-dev.
https://code.google.com/p/pyodbc/issues/detail?id=55
I did it, and then the pip install success.
Hope this helpful.
Upvotes: -1
Reputation: 178
This worked for me after trying just about everything else suggested.
brew install unixodbc
sudo pip install --upgrade --global-option=build_ext --global-option="-I/usr/local/include" --global-option="-L/usr/local/lib" --allow-external pyodbc --allow-unverified pyodbc pyodbc
Running Mac OS 10.11.1,Homebrew 0.9.5, and pip 7.1.2
Upvotes: 10
Reputation: 11
I just went through the whole process on Mac OS X; connecting to pyodbc to MS SQL Server 2014. The whole process is as follows:
Connection pipeline:
pyodbc ----> iodbc ----> freetds ----> MS SQL Server 2014
Build freetds (the SQL Server driver/connector):
./configure --prefix=/usr/local --with-tdsver=8.0
make
sudo make install
// you should see /usr/local/lib/libtdsodbc.so was generated
//test method 1:
TDSVER=8.0 tsql -H hostname -p 1433 -U username -P XXX -D databasename
//test method 2:
//config /usr/local/etc/freetds.conf
[mssqlserver]
host = XXX
port = 1433
tds version = 8.0
//run
tsql -S mssqlserver -U username -P XXX -D databasename
//if you can run sql, good to go!
Build iodbc (ODBC manager):
//download from github, go to the folder
cd mac
./configure
./make
sudo ./make install
//config /usr/local/etc/odbc.ini
[mssqlserver]
Driver=/usr/local/lib/libtdsodbc.so
TDS_Version=8.0
Server=xxxx
Port = 1433
Trace = Yes
Description=XXX
//test
which iodbctest
iodbctest
DSN=masqlserver;UID=xxx;PWD=xxx
//if you can run sql, good to go!
Connect pyodbc (Python ODBC wrapper) to iodbc:
pip install pyodbc
//in python,
conn = pyodbc.connect("DSN=mssqlserver;UID=xxx;PWD=xxxx")
Upvotes: 1
Reputation: 1198
After many dead ends, this worked for me:
$ brew unlink unixodbc
$ brew install unixodbc --universal
$ sudo pip install --upgrade --global-option=build_ext --global-option="-I/usr/local/include" --global-option="-L/usr/local/lib" --allow-external pyodbc --allow-unverified pyodbc pyodbc
Upvotes: 31
Reputation: 12198
See my installation instructions which I've written after some futile attempts of the other answers provided:
First, install the following libraries:
$ brew install unixodbc
$ brew install freetds --with-unixodbc
FreeTDS should already work now, without configuration:
$ tsql -S [IP or hostname] -U [username] -P [password]
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1> ^D
Onto unixODBC, we need to link to the driver, edit /usr/local/etc/odbcinst.ini
:
[FreeTDS]
Description = TD Driver (MSSQL)
Driver = /usr/local/lib/libtdsodbc.so
Setup = /usr/local/lib/libtdsodbc.so
FileUsage = 1
The test command we're using requires configuring a DSN, so edit /usr/local/etc/odbc.ini
:
[MYDSN]
Driver = FreeTDS
Server = [IP address]
Port = 1433
The configuration for your DNS might vary, you might need the TDS_Version
or Servername
directives. The above worked for me for SQL Server 2008 R2. Now, run the test command:
$ isql MYDSN [username] [password] -v
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL> ^D
If the test succeeded, you can continue onto installing the Python library pyodbc
. The current version of writing (3.0.7) doesn't link with unixODBC on OS X, so a change has to be made to setup.py
. Download the source package and extract it somewhere. Find the following lines (146-147):
elif sys.platform == 'darwin':
# OS/X now ships with iODBC.
And change this line:
settings['libraries'].append('iodbc')
into:
settings['libraries'].append('odbc')
Then run the following command to install:
> python install .
Now pyodbc should work:
import pyodbc
pyodbc.connect('DSN=MYDSN;UID=[username];PWD=[password]')
You don't need to have your DSN configured in odbc.ini
, so clear that file. You probably want to select a database on connect, so change your connect line to read:
pyodbc.connect('DRIVER=FreeTDS;SERVER=[IP address];PORT=1433;DATABASE=[database];UID=[username];PWD=[password]')
Note that you could also link to the library file of FreeTDS instead of using odbcinst.ini
, like this:
pyodbc.connect('DRIVER=/usr/local/lib/libtdsodbc.so;SERVER=[IP address];PORT=1433;DATABASE=[database];UID=[username];PWD=[password]')
Upvotes: 14
Reputation: 1209
If you see errors like
clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]
The problem is that with Mavericks Apple has removed gcc from the command line developer tools; it is now clang just symlinked to gcc. The --mno-fused-madd
flag is not supported by clang (same goes for lots of other flags).
One solution might be to install gcc using homebrew or another method and symlink /usr/bin/gcc to a proper gcc.
A simpler workaround that worked for me is suppressing these error by turning them into warnings:
export CFLAGS=-Qunused-arguments
After settings that I was able to pip install pyodbc
without errors.
PS! In future versions of clang this might not be possible. At least it works on:
$> gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix
Refs:
https://bitbucket.org/cffi/cffi/issue/46/unused-mno-fused-madd-clang-warnings-on-os
https://coderwall.com/p/lqpp8w
clang: error: unsupported option '-static-libgcc' on Mac OSX Mavericks
Upvotes: 2
Reputation: 681
You can use Homebrew to install unixodbc, then pyodbc via pip in the usual fashion.
brew install unixodbc && pip install pyodbc
This works for me on Mavericks.
Upvotes: 63
Reputation: 19827
I had no joy with @Vitaly's answer because there appears to be an issue building packages on Mavericks to do with the lack of support for hard-linking. I couldn't get the package to build.
So I opted for @Vitaly's second suggestion which was to copy the necessary files from the [libiodbc_sources]/include/
directory to /usr/include
and the install worked find. Here is a list of the files you will need to copy:
Upvotes: 10
Reputation: 11952
As you noticed OSX Mavericks dropped sql headers that are required for PyODBC compilation. Following these steps allowed me to install PyODBC:
pip install --no-install pyodbc
cd [VIRTUAL_ENV]/build/pyodbc
python setup.py build_ext --include-dirs=[LIBIODBC_SOURCES]/include/
Run pip install --no-download pyodbc
:
Installing collected packages: pyodbc
Running setup.py install for pyodbc
warning: no files found matching 'tests/*'
Successfully installed pyodbc
Cleaning up...
I could as well copy the files under [libiodbc_sources]/include/
to my /usr/include
and just run pip install pyodbc
, but I didn't want to add files manually to system folders.
Upvotes: 32