I am trying to connect to a MS SQL database and get some values over a Raspberry Pi. I have my Python script and it works well on windows, but i dont know how to install the 'pyodbc' module on the PI.

Does the 'pyodbc' work on the PI? Thanks in advance :)

  • try pip install pyodbc (you may need to use sudo to install successfully. – Steve Robillard Jan 22 '17 at 7:20

Whenever possible use apt-get to install packages on Raspbian.

You can then be sure the package will be consistent with the rest of the installed packages.

Search for candidates as follows

$ apt-cache search odbc | grep python

python-egenix-mxdatetime - date and time handling routines for Python
python-pyodbc - Python module for ODBC database access
python-pyodbc-dbg - Python module for ODBC database access - Debugging symbols

Install as follows (say y at the prompt to install)

$ sudo apt-get install python-pyodbc

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
Suggested packages:
  libmyodbc odbc-postgresql tdsodbc unixodbc-bin
The following NEW packages will be installed:
  libodbc1 python-pyodbc
0 upgraded, 2 newly installed, 0 to remove and 1 not upgraded.
Need to get 225 kB of archives.
After this operation, 610 kB of additional disk space will be used.
Do you want to continue? [Y/n] 

PI to SQL Server works as of 7/29/2018. I am much better at MS SQL than Raspbian or Linux and the Pi, but it does work. Setting it up requires a little documentation from everywhere. Python 2 and Python 3 are both installed on the Pi for the newest Raspbian OS. You must be sure pyodbc is installed on Python 3 and the driver is setup and configured. If not, the first statement --> import pyodbc will fail.

Ok here is a good head start there are several components you will need.

https://tryolabs.com/blog/2012/06/25/connecting-sql-server-database-python-under-ubuntu/ is a great place to start.

After you go through their docs. A note about /etc/odbcinst.ini file.
Below is a command to edit it easily.

sudo nano /etc/odbcinst.ini

Your drivers will located a different place for the PI in the odbcinst.ini file.

These were double checked this is where mine were installed. Driver = /usr/lib/arm-linux-gnueabi/odbc/libtdsodbc.so Setup = /usr/lib/arm-linux-gnueabi/odbc/libtdsS.so Fix this.


This helped me get mine working.

Last minute change to get python 3 working and the next held me up a while sudo apt-get install python3-pymysql

This last command fixed me. sudo dpkg-reconfigure tdsodbc

These commands might help pip3 list pip list

After all this is done, hopefully you will be closer to yours working after this. I have it working with Python 2 and 3 and Tkinter. I also have it working on Windows IoT Core on the Pi. My little video shows the speed and that yes it can work very well, I just had to show it.


Again this is not the best way to access the database unless you have complete control of the network. You should use a Rest or Web Services process across the web. It is much more secure.

I will try and put all this together in a document when I can find time to try it from a fresh Pi Raspbian build.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.