My favorites | Sign in
Project Home Downloads Wiki Issues Source
Building pyodbc
Updated Jul 28, 2011 by mkleehammer


Obtaining Source

The source for released versions are provided in zip files on the Downloads page.

If you are going to work on pyodbc (changes are welcome!), use the git repository on github. (Even better, create a fork on github so I can easily pull changes from your fork.)

If you want an unreleased version from github but don't have git installed, choose the branch and commit you want and use the download button. It will offer you a tar or zip file.


pyodbc is built using distutils, which comes with Python. If you have the appropriate C++ compiler installed, run the following in the pyodbc source directory:

python build

To install after a successful build:

python install


pyodbc uses git tags in the format major.minor.patch for versioning. If the commit being built has a tag, such as "2.1.1", then that is used for the version. If the commit is not tagged, then it is assumed that the commit is a beta for an upcoming release. The patch number is incremented, such as "2.1.2", and the number of commits since the previous release is appended: 2.1.2-beta3.

If you are building from inside a git repository, the build script will automatically determine the correct version from the tags (using git describe).

If you downloaded the source as a zip from the Downloads page, the version will be in a PGK-INFO text file. The build script will read the version from the text file.

If the version cannot be determined for some reason, you will see a warning about this and the script will build version 2.1.0. Do not distribute this version since you won't be able to track its actual version!

Operating Systems


On Windows, you will need the appropriate Microsoft Visual C++ compiler. To build Python 2.4 or 2.5 versions, you will need the Visual Studio 2003 .NET compiler. Unfortunately there is no free version of this.

For Python 2.6 and above, you can use the free Visual C++ 2008 Express compiler. (Do not use the 2010 version! You need to use the version that your Python distribution was built with.)

You can create a Windows installer using:

python bdist_wininst


To build on other operating systems, use the gcc compiler.

On Linux, pyodbc is typically built using the unixODBC headers, so you will need unixODBC and its headers installed. On a RedHat/CentOS/Fedora box, this means you would need to install unixODBC-devel:

yum install unixODBC-devel
Comment by, Dec 29, 2008

If compiling for Ubuntu (and possibly other flavors of Linux) you'll need the unixODBC-dev package.

sudo apt-get install unixODBC-dev

Comment by, Feb 16, 2009


Sorry I did not find any way to contact you hence adding a comment here. I have an application which was developed in Python 2.3 and now they want to add MS SQL Server support to it. I was searching for the connection on windows when I came across this project. But I am not finding any installer for Python 2.3. Can you please let me know how can I connect to MS SQL Server using Python 2.3

You can contact me at

Comment by, Apr 9, 2009

You might want to try the Google group here:

Comment by, Nov 6, 2009

To avoid gcc error on Ubuntu Linux, I did:

$ sudo aptitude install g++

I also installed the following 2 packages from Synaptic:

  • python-dev
  • tdsodbc

To avoid 'no default driver specified' error when connecting to MSSQL db, I had to create /etc/odbcinst.ini and put the following entry:

[SQL Server]
Description = TDS driver (Sybase/MS SQL)
Driver      = /usr/lib/odbc/
Setup       = /usr/lib/odbc/
CPTimeout   =
CPReuse     =


Comment by, Feb 11, 2011
Comment by, Jan 20, 2012

What do I do wrong? I get stuck with error after

git clone
cd pyodbc
git checkout 3.0.2
python install
Traceback (most recent call last):
  File "", line 270, in <module>
  File "", line 61, in main
    version_str, version = get_version()
  File "", line 212, in get_version
    name, numbers = _get_version_git()
  File "", line 255, in _get_version_git
    branch ='\* (\w+)', result).group(1)
AttributeError: 'NoneType' object has no attribute 'group'
Comment by, May 31, 2012

<wiki:comment> After the 3.0.2 version of pyodbc was built and installed on centos6.1, the pyodbc can still not work. After "import pyodbc", "conn" and "conn.commit()", a simple sentence such as "select * from dbcinfo" can not work on "cur.execute('select * from dbcinfo')". However, in the "client" samples written with C++, "./adhoc" can illustrate that odbc on teradata really work on "cur.execute('select * from dbcinfo')". Thus, there should be something wrong with 3.0.2, which is used to wrap C or C++ for python. </wiki:comment>

Comment by, May 31, 2012

I got the bug through the following process: (1) install unixodbc-dev (2) install teradata's odbc for 64 (3) install the corresponding package with the help of strace (4) check the validation of client on centos (5) make the samples supplied by C++ (6) run the command "./adhoc" in the folder "/opt/teradata/client/13.10/odbc_64/samples/C++" (7) the command remind a SQL sentence (8) input the SQL liking in "Teradata SQL Assistant" (9) get the normal result (10) walk into python environment with python command on centos (11) test connect teradata with typical python commands (12) on the step "cur.execute('select from dbcinfo')", a strange error is: Traceback (most recent call last):

File "<stdin>", line 1, in <module>
pyodbc.Error: ('400', '400? [eaaarvr[eaaaDtbs?Sna ro:epce oehn ewe h einn fterqetadtewr s. (-3706) (SQLExecDirectW)')

Comment by, Oct 18, 2012

how can i compile the pyodbc3.0.6 for python 3.3 on a win7 system?there is a error message is "Unable to find vcvarsall.bat".vs2008 installed.

Comment by, Jan 10, 2013
Comment by, Nov 22, 2013


I downloaded and built pyodbc on Redhat Linux, it built and installed fine. But now import pyodbc from python prompt fails with this error: ImportError?: No module named pyodbc

Can you please help? Thanks!

Comment by, Jan 22, 2014

$ sudo apt-get install unixODBC-dev

$ sudo apt-get install g++

$ sudo apt-get install python-dev

$ sudo apt-get install tdsodbc

download and extract the odbc source code (

run the setupfile in the extracted directory: python build sudo python install

Comment by, Feb 11, 2014

I built and installed pyodbc (v. 3.0.7) on a system with python 2 and 3 installed. For the python 3 version, all I needed to do was to replace 'python' by 'python3' in the above commands: $ sudo apt-get install python3-dev $... sudo python3 pyodbc build sudo python3 pyodbc install This allows me to test gradually convert the necessary programs from python 2.x to python 3.

Sign in to add a comment
Powered by Google Project Hosting